How can a module know the module that imported it?
AK Eric
warpcat at sbcglobal.net
Thu Nov 12 12:49:53 EST 2009
so:
# moduleA.py
import moduleB
# moduleB.py
import sys
stuff = sys._getframe(1).f_locals
print stuff
Prints:
{'__builtins__': <module '__builtin__' (built-in)>,
'__file__': 'C:\\Documents and Settings\\<userName>\\My Documents\
\python\\moduleA.py',
'__name__': '__main__',
'__doc__': None}
Looks like you could query stuff['__file__'] to pull what you're
after.
?
More information about the Python-list
mailing list