who to call a list of method inside the class itself

Diez B. Roggisch deets at nospam.web.de
Tue Aug 19 12:07:00 EDT 2008


Edwin.Madari at VerizonWireless.com wrote:

> fredrik at pythonware.com wrote:
>> 
>> Edwin.Madari at VerizonWireless.com wrote:
>> 
>> > 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



More information about the Python-list mailing list