iteration over methods

Oliver Vecernik vecernik at aon.at
Tue Jan 7 07:12:12 EST 2003


Padraig Brady schrieb:
> How about:
> 
> class Someclass:
>     def __init__(self):
>         pass
>     def method1(self):
>         pass
>     def method2(self):
>         pass
>     def runallmethods(self):
>         for name, func in self.__class__.__dict__.items():
>             if name[0:6] == 'method':
>                 func(self)

Well, I just see:

__module__
__doc__
__init__

But I didn't tell the whole story. Actually this class is subclassed:

class Subclass(Someclass):
     def __init__(self):
         pass
...

def main():
     ref = Subclass
     ref.runallmethods()
...

All other methods are inherited from 'Someclass'. Sometimes 'Subclass' 
may overload some methods, but in general they should be inherited. Is 
there also a possiblity to iterate over all of them?

Best Regards,
Oliver





More information about the Python-list mailing list