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?
+2
A:
If you have a class in that module, then the __module__
property of the class is the module of the class.
Michael
2009-11-04 21:46:01
+3
A:
You can get the name of the current module using __name__
The module reference can be found in the sys.modules
dictionary.
See the Python documentation
pkit
2009-11-04 21:46:41
__main__ is only the module name if it's run as a script: if you import the module this won't work.
mavnn
2009-11-04 21:50:26
DOH! Typo, edited.
pkit
2009-11-04 22:01:18