Connecting Tech Pros Worldwide Forums | Help | Site Map

Re: who to call a list of method inside the class itself

Edwin.Madari@VerizonWireless.com
Guest
 
Posts: n/a
#1: Aug 19 '08
fredrik@pythonware.com wrote:
Quote:

Edwin.Madari@VerizonWireless.com wrote:
Quote:
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
why?
ensure instance's method invocation with all state information to that point, rather than relying on implemenation.

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.



Diez B. Roggisch
Guest
 
Posts: n/a
#2: Aug 19 '08

re: Re: who to call a list of method inside the class itself


Edwin.Madari@VerizonWireless.com wrote:
Quote:
fredrik@pythonware.com wrote:
Quote:
>>
>Edwin.Madari@VerizonWireless.com wrote:
>>
Quote:
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
>>
>why?
>
ensure instance's method invocation with all state information to that
point, rather than relying on implemenation.
Erm, that makes no sense. The OP's code was perfectly fine - for some reason
he seemed to think it wasn't.

Your additional indirection doesn't add anything beyond clutter, as

name = "foo"
getattr(instance, name) == instance.foo

holds.

Diez
Closed Thread