who to call a list of method inside the class itself
Edwin.Madari at VerizonWireless.com
Edwin.Madari at VerizonWireless.com
Tue Aug 19 10:53:49 EDT 2008
maduma at pt.lu 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
regards.
Edwin
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.
More information about the Python-list
mailing list