identifying invoking module from imported function
Andy Beall
beall at space.mit.edu
Thu May 6 09:43:06 EDT 1999
Is it possible to for a called function to identify the name of a module
from which the function was called when that function resides in a
module that was imported into the first module? I guess I'm looking for
something like __name__ but which will give the name of the "parent"
module. Here's an example of what I'm trying to find:
------------------------ scriptA.py -------------------------------
import scriptB
foo()
------------------------ scriptB.py -------------------------------
def foo():
print 'Name of this module is ', __name__
print 'Name of calling module is ', ?????
----------------------- DESIRED OUTPUT ---------------------
>>> scriptB
>>> scriptA
My apologies if this is obvious how to do because I have spent several
hours trying different things with no luck.
Thanks,
Andy-
More information about the Python-list
mailing list