iteration over methods

John Roth johnroth at ameritech.net
Tue Jan 7 08:14:37 EST 2003


"Oliver Vecernik" <vecernik at aon.at> wrote in message
news:3E1AB7B3.4050404 at aon.at...
> Hi!
>
> I've got an object with some methods:
>
> class Someclass(self):
>      def __init__(self):
>          pass
>      def method1(self):
>          pass
>      def method2(self):
>          pass
>      ...
>      def runallmethods(self):
>          for func in dir(self):
>              if func[0:4] == 'method':
>                  apply(self.func) # Does *not* work!
>
> I'd like to run all methods named 'method...' in a sequence. Has
anybody
> a clue how to achive this?

Look at the "unittest" module. It does exactly this.

John Roth
>
> Best Regards,
> Oliver
>






More information about the Python-list mailing list