How can I access the current executing module or class name in Python?

前端 未结 11 1847
醉酒成梦
醉酒成梦 2020-12-05 01:30

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:

11条回答
  •  爱一瞬间的悲伤
    2020-12-05 02:11

    It's been a while since I've done python, but I believe that you can get access to the globals and locals of a caller through its traceback.

提交回复
热议问题