What is the "optimal" way to list all class methods of a given class using inspect
? It works if I use the inspect.isfunction
as predicate in getmembers
like so
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 isn't it supposed to work via ismethod
?
inspect.getmembers(MyClass, predicate=inspect.ismethod)
which returns an empty list in this case. Would be nice if someone could clarify what's going on. I was running this in Python 3.5.