Ben
Ben

Reputation: 2472

How can I list methods directly defined in a class (not inherited)?

I am looking for something along the lines of dir(), but want to filter out non-instancemethods and attributes that are defined in super class/es.

Upvotes: 0

Views: 91

Answers (1)

kindall
kindall

Reputation: 184455

for python 2.x:

[name for name, method in Class.__dict__.iteritems() if callable(method)]

for python 3.x:

[name for name, method in Class.__dict__.items() if hasattr(method,'__call__')]

Upvotes: 4

Related Questions