Help in using introspection to simplify repetitive code

Simon Percivall percivall at gmail.com
Sun Aug 20 12:45:46 EDT 2006


jsceballos at gmail.com wrote:
> Hello.
> I'm writing a proxy class, i.e: a class whose methods mostly delegate
> their functionality to other class object. Most of the methods (which
> are quite a lot) defined in the class would end up being:
>
> def thisIsTheMethodName(self):
>     self._handlerClass.thisIsTheMethodName()
>
> The handler object is the same in all methods.
>
> I was wondering if there is a way to simplify this proxy class, maybe
> using some pythonic technique like metaclasses, introspection... any
> suggestion is appreciated.
>
> Thanks,
>
> Javier Sanz

http://docs.python.org/ref/attribute-access.html#l2h-206




More information about the Python-list mailing list