Finding all of a classes methods?
Mark McEahern
marklists at mceahern.com
Sun Feb 3 20:58:43 EST 2002
Roy Smith:
> Is there any way to find all of a class's methods?
There's probably a better way than this, but it seems to work plus it might
give you some ideas...
#! /usr/bin/env python
import inspect
def runall(obj):
all = inspect.getmembers(obj, inspect.ismethod)
for methodTuple in all:
methodTuple[1]()
class foo:
def bar(self):
print "bar"
def bar2(self):
print "bar2"
f = foo()
runall(f)
More information about the Python-list
mailing list