Thursday, December 18, 2008

Nabble - Python - python-list - How to get current module object

Nabble - Python - python-list - How to get current module object: "

C:\junk>type whoami.py
def showme():
import sys
modname = globals()['__name__']
print repr(modname)
module = sys.modules[modname]
print repr(module)
print dir(module)


C:\junk>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type 'help', 'copyright', 'credits' or 'license' for more information.
>>> import whoami
>>> whoami.showme()
'whoami'
<module 'whoami' from 'whoami.py'>
['__builtins__', '__doc__', '__file__', '__name__', 'showme']"

No comments: