[EMAIL PROTECTED] a écrit :
[EMAIL PROTECTED] wrote:
Hi,

Is the following code is ok. who to call all method.
It is working but the call to m() without a reference to self seems
strange

Thanks for your help

class CustomMethod:
    def method1(self):
        ....
    def method2(self):
        ....
    def method3(self):
       ....

    def getAllMethod(self):
        return [self.method1, self.method2, self.method3]

    def applyAll(self):
        for m in self.getAllMethod():
            # how to call all methods ?
            # is it correct
            m()

1. return string names of required methods in getAllMethod
        return ['method1', 'method2', 'method3']
2. use gettattr on self and then exetute methods in applyAll
        def applyAll(self):
            for method_name in self.getAllMethod():
                method = gettattr(self,method_name)
                  method() #execute method now


Except for extra lookup time, what would this buy you ???
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to