Issue
Here is some code that runs with no problem:
When I hover over the warning triangles, Spyder tells me that datetime
and vstack
are "undefined". But they seem to be defined, since the code runs. How can I make those warning triangles go away?
Copy-able code here:
# -*- coding: utf-8 -*-
#%%
import numpy as np
x = np.array([0, 1, 2])
this_year = datetime.date.today().year
y = vstack((x,x))
#%%
Solution
import datetime and use np.vstack
You have not imported the datetime
module and vstack
is part of numpy
which you imported as np
.
I don't see how the code could run without importing datetime and using np.vstack.
Typing the commands into ipython gives NameError: name 'datetime' is not defined
:
In [3]: import numpy as np
In [4]: x = np.array([0,1,2])
In [5]: this_year = datetime.date.today().year
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-5-a5c59948ea66> in <module>()
----> 1 this_year = datetime.date.today().year
NameError: name 'datetime' is not defined
your code runs because I think there is a site-packages/spyderlib/scientific_startup.py
that imports modules automatically, numpy
is included as must datetime
.
Answered By - Padraic Cunningham
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.