iteration over methods

Padraig Brady padraig.brady at corvil.com
Tue Jan 7 13:25:28 CET 2003


Well then, how about:

class baseClass:
     def method1(self):
         print "Base1"
     def method3(self):
         print "Base2"

class Someclass(baseClass):
     def __init__(self):
         pass
     def method1(self):
         print "Sub1"
     def method2(self):
         print "Sub2"
     def runallmethods(self):
         for name in dir(self):
             if name[0:6] == 'method':
                 getattr(self, name)()

mc = Someclass()
mc.runallmethods()

Pádraig.





More information about the Python-list mailing list