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

murftown picture murftown · Apr 1, 2011 · Viewed 28.1k times · Source

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

Answer

Catskul picture Catskul · Jul 30, 2012

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