Looping over a Python / IronPython Object Methods
问题 What is the proper way to loop over a Python object's methods and call them? Given the object: class SomeTest(): def something1(self): print "something 1" def something2(self): print "something 2" 回答1: You can use the inspect module to get class (or instance) members: >>> class C(object): ... a = 'blah' ... def b(self): ... pass ... ... >>> c = C() >>> inspect.getmembers(c, inspect.ismethod) [('b', <bound method C.b of <__main__.C object at 0x100498250>>)] getmembers() returns a list of