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__ to b.foo method)...
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__
2.1m questions
2.1m answers
60 comments
57.0k users