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__
1.4m articles
1.4m replys
5 comments
57.0k users