getattr() on nested functions?
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Thu Aug 21 08:03:31 EDT 2008
Gabriel Rossetti a écrit :
> Terry Reedy wrote:
(snip)
>> Unlike the class approach, this requires recreating the constant
>> functions and dict with each call to _test. Quick to write but a bit
>> 'dirty', in my opinion. Another standard idiom is to set up the
>> constants outside the function:
>>
>> def request(params):
>> pass
>> def submit(params, values):
>> pass
>> def update(params, values):
>> pass
>> def delete(params):
>> pass
>> dispatch = {'request':request, 'submit':submit, 'update':update,
>> 'delete':delete}
>>
>> def _test(self, action, *args):
>> return resultToXmo(dispatch[action](*args))
>
> That's how I had done it originally (before the use of eval()), but in
> this case also, since the functions are still nested,
Uh ??? You probably want to re-read the above code snippet.
More information about the Python-list
mailing list