I'm using python 3.2.2. When I write a simple program, I meet the problem.
>>> reload(recommendations) Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> reload(recommendations) NameError: name 'reload' is not defined
How should I do it?
The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.
The reload() - reloads a previously imported module or loaded module. This comes handy in a situation where you repeatedly run a test script during an interactive session, it always uses the first version of the modules we are developing, even we have mades changes to the code.
An update to @Gareth Latty's answer. imp
was depreciated in Python 3.4. Now you want importlib.reload()
.
from importlib import reload
You probably wanted importlib.reload()
.
from importlib import reload
In Python 2.x, this was a builtin, but in 3.x, it's in the importlib
module.
Note that using reload()
outside of the interpreter is generally unnecessary, what were you trying to do here?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With