如何从函数中获取调用者对象,并检查有关该调用者的信息?
class A(object):
def class_A_fun(self):
print 'caller from class' # → B
print 'caller from method' # → class_B_fun
print 'caller module' # → foomodule
print 'caller instance' # → obj
print 'caller object file name or path' # → 'foomodule.py'
class B(object):
def class_B_fun(self):
obj = A()
obj.class_A_fun()
if __name__ == "__main__":
obj = B()
obj.class_B_fun()