Use getattr(a,methodname) to access the actual method, given the string name, methodname :
import inspect import types class Test(object): def methodOne(self): print('one') def methodTwo(self): print('two') a = Test() methodList = [n for n, v in inspect.getmembers(a, inspect.ismethod) if isinstance(v,types.MethodType)] for methodname in methodList: func=getattr(a,methodname) func()
gives
one two
As Jochen Ritzel points out, if you are more interested in actual methods (called objects) than method names (strings), then you should change the definition from methodList to
methodList = [v for n, v in inspect.getmembers(a, inspect.ismethod) if isinstance(v,types.MethodType)]
so that you can directly call methods without requiring getattr :
for method in methodList: method()
source share