How to get a reference to a module inside the module itself?

Ram Rachum picture Ram Rachum · Nov 4, 2009 · Viewed 61.9k times · Source

How can I get a reference to a module from within that module? Also, how can I get a reference to the package containing that module?

Answer

truppo picture truppo · Nov 4, 2009
import sys
current_module = sys.modules[__name__]