Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
whenever I try to reload a python module in python version 3.3.2 i get this error code
>>> import bigmeesh
>>> bob=bigmeesh.testmod()
this baby is happy
>>> imp.reload(bigmeesh)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
imp.reload(bigmeesh)
NameError: name 'imp' is not defined
I tried researching and still got no answers.
You have to import imp
before you can use it, just as with any other module:
>>> import bigmeesh
>>> import imp
>>> imp.reload(bigmeesh)
However, in 3.3, importlib
doesn't have a simple reload
function; you'd have to build it yourself out of importlib.machinery
. So, for 3.3, stick with imp
. But in 3.4 and later which do have importlib.reload
, use that instead.
It's also worth noting that reload
is often not what you want. For example, if you were expecting bob
to change into an instance of the new version of bigmeesh.testmod()
, it won't. But, on the other hand, if you were expecting it to not change at all, you might be surprised, because some of its behavior might depend on globals that were changed.
–
–
Just type modulereload(MODULE_NAME)
, replacing MODULE_NAME
with the name of the module you want to reload.
For example, modulereload(math)
will reload the math function.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.