What is the best way to list all the class methods of a given class with inspect
? It works if I use inspect.isfunction
as a predicate in getmembers
, for example,
class MyClass(object):
def __init(self, a=1):
pass
def somemethod(self, b=1):
pass
inspect.getmembers(MyClass, predicate=inspect.isfunction)
returns
[('_MyClass__init', <function __main__.MyClass.__init>),
('somemethod', <function __main__.MyClass.somemethod>)]
But shouldn't he work through ismethod
?
inspect.getmembers(MyClass, predicate=inspect.ismethod)
which returns an empty list in this case. It would be nice if someone could clarify what was happening. I ran this in Python 3.5.
source
share