for example, a.boo method calls b.foo method. In b.foo method, how can I get a\'s file name (I don\'t want to pass __file__
a.boo
b.foo
__file__
You can use the inspect module to achieve this:
inspect
frame = inspect.stack()[1] module = inspect.getmodule(frame[0]) filename = module.__file__