Help in using introspection to simplify repetitive code

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sun Aug 27 16:07:11 EDT 2006


jsceballos at gmail.com a écrit :
> As you mention, wether the methods take arguments or not is something
> to have into account.
> And they do take arguments, and a variable number of them, so AFAIK
> hooking with __getattr__ or __getattribute__ will not work, as you can
> only get the method name with that.

Nope. Defining __getattr__ is the canonical pythonic way to do 
delegation. Remember that in Python, functions and methods are objects 
too and can be passed around/returned etc just like any other object.




More information about the Python-list mailing list