Python 如何列出类中直接定义的方法(不是继承的)?

Python 如何列出类中直接定义的方法(不是继承的)?,python,Python,我正在寻找类似于dir()的内容,但希望筛选出在超级类/es中定义的非实例方法和属性。对于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__')] 对于Python2.x: [name for

我正在寻找类似于
dir()
的内容,但希望筛选出在超级类/es中定义的非实例方法和属性。

对于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__')]
对于Python2.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__')]

在我看来,
inspect
应该做得更好一些。。。(但我不确定——我还没有看)在我看来,
inspect
应该有更好的功能来完成这项工作。。。(但我不确定——我还没看过)