Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload python module imported using `from module import *`

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? :)

like image 657
murftown Avatar asked Apr 01 '11 17:04

murftown


People also ask

How do I reload an imported module in Python?

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.

How do you reload a function in Python?

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.


1 Answers

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 
like image 164
Catskul Avatar answered Sep 18 '22 06:09

Catskul