how to get the caller's filename, method name in python

后端 未结 6 1510
别那么骄傲
别那么骄傲 2020-12-05 13:46

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__

6条回答
  •  粉色の甜心
    2020-12-05 14:31

    you can use the traceback module:

    import traceback
    

    and you can print the back trace like this:

    print traceback.format_stack()
    

    I haven't used this in years, but this should be enough to get you started.

提交回复
热议问题