Is it possible to get “importing module” in “imported module” in Python?

前端 未结 4 2009
暖寄归人
暖寄归人 2021-01-15 11:52

For imported module, is it possible to get the importing module (name)? I\'m wondering if inspect can achieve it or not~

4条回答
  •  隐瞒了意图╮
    2021-01-15 12:11

    It sounds like you solved your own problem: use the inspect module. I'd traverse up the stack until I found a frame where the current function was not __import__. But I bet if you told people why you want to do this, they'd tell you not to.

提交回复
热议问题