I saw in this useful Q&A that one can use reload(whatever_module)
or, in Python 3, imp.reload(whatever_module)
.
My question is, what if I had said from whatever_module import *
to import? Then I have no whatever_module
to refer to when I use reload()
. Are you guys gonna yell at me for throwing a whole module into the global namespace? :)
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.
You can't reload a method from a module but you can load the module again with a new name, say foo2 and say bar = foo2. bar to overwrite the current reference.
I agree with the "don't do this generally" consensus, but...
The correct answer is:
import X reload(X) from X import Y # or * for that matter
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