python 看函数被谁调用

在一个函数中
def fun():

    pass
这个函数如何知道是谁调用了它呢?
import traceback
def fun():
      s =  traceback.extract_stack()
      print '%s Invoked me!'%s[-2][2]


这个 fun 函数就可以知道是谁调用了它,并打印出来:
 
def a():

     fun()


def b():

     fun()

a()
a Invoked me!


b()
b Invoked me!

原文地址:https://www.cnblogs.com/yuzhaoblog/p/12395950.html