How to inspect who is caller of func and who is the class of instance
2015-06-15 16:51
585 查看
1. Who is the class of self instance ?
2.Who is the caller of function
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>
相关文章推荐
- joomla安装
- map 容器(copy)
- sprite图在移动端的使用
- 关于UITableView的一些用法
- 双缓存
- 组合还是继承
- Matt Cutts 称记者说 Google “do no evil” 是找茬儿,应该是 “don't be evil”
- 关键字PASCAL
- Android的Menu菜单详解(二)
- grid搜索最优参数
- HTML meta头部小结
- MatLab之Simulink之simple model
- Solr相似度算法三:DRFSimilarity
- SD--批量删除订单
- 某企业“金融云计算之架构视角”内训圆满结束!
- Error: Error parsing D:\android-sdk-windows\sdk\system-images\android-22\android-wear\x86\devices.xm
- Android中linux内核模块--开发设备驱动程序 && 上层接口实施 (二)
- 写了个支持日志的内存数据库
- 报错error:Error parsing XML:unbound prefix的解决办法
- 正则表达式基本语法