Decorating methods - where do my arguments go?

Mikael Olofsson mikael at
Tue May 12 08:54:22 CEST 2009

Peter Otten wrote:
> I usually use decorator functions, but I think the following should work, 
> too:
> class deco(object):
>     def __init__(self, func):
>         self._func = func
>     def __call__(self, *args):
>         print "Decorator:", args
>         self._func(*args)
>     def __get__(self, *args):
>         return deco(self._func.__get__(*args))

This looks like a winner to me. It is elegant, works for functions as 
well as for methods, and does not mess with the internals of the 
decorator which avoids the problems that Duncan pointed out.

Thanks Peter, and thanks everyone else that chimed in and contributed.


More information about the Python-list mailing list