I would like to be able to dynamically retrieve the current executing module or class name from within an imported module. Here is some code:
foo.py:
def f():
print __name__
bar.py:
from foo import f
def b(): f()
This obviously does not work as __name__ is the name of the module that contains the function. What I would like to be access inside the foo module is the name of the current executing module that is using foo. So in the case above it would be bar but if any other module imported foo I would like foo to dynamically have access to the name of that module.
Edit: The inspect module looks quite promising but it is not exactly what I was looking for. What I was hoping for was some sort of global or environment-level variable that I could access that would contain the name of the current executing module. Not that I am unwilling to