![](/img/trans.png)
[英]How do i tell from a list of methods, which ones have been defined in that class and those that have been inherited?
[英]How can I list methods directly defined in a class (not inherited)?
我正在寻找dir()
,但想过滤掉超类中定义的非实例方法和属性。
对于python 2.x:
[name for name, method in Class.__dict__.iteritems() if callable(method)]
对于python 3.x:
[name for name, method in Class.__dict__.items() if hasattr(method,'__call__')]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.