标签:
1. Who is the class of self instance ?
class aa(object): def a(self): if self.__class__.__name__ == ‘aa‘: print "aa, a func()" elif self.__class__.__name__ == "bb": print "bb, a func()" class bb(aa): def b(self): print "aa, b func()" aa().a() bb().a() --------------------------------------------------------------------- result : aa, a func() bb, a func()
2.Who is the caller of function
import inspect class aa(object): def a(self): frame = inspect.currentframe() print "The caller is %s" %frame.f_back.f_code.co_name def callerOfa(self): self.a() aa().callerOfa() aa().a() --------------------------------------------------------------- result: The caller is callerOfa The caller is <module>
How to inspect who is caller of func and who is the class of instance
标签:
原文地址:http://www.cnblogs.com/root-wang/p/4578639.html