From: Michele Simionato on
Another option is to use my own decorator module (http://
pypi.python.org/pypi/decorator):

from decorator import decorator

@decorator
def d(func, *args):
print 3
return func(*args)

@d
def f(a, b):
print a + b

f(5, 7)


From: Patrick Maupin on
On Mar 28, 9:17 am, Michele Simionato <michele.simion...(a)gmail.com>
wrote:
> Another option is to use my own decorator module (http://
> pypi.python.org/pypi/decorator):
>
> from decorator import decorator
>
> @decorator
> def d(func, *args):
>     print 3
>     return func(*args)
>
> @d
> def f(a, b):
>     print a + b
>
> f(5, 7)

That looks cool (and I'm glad you mentioned it), but it appeared to me
the OP was trying to manually construct the equivalent of a decorator
without the "@" syntax, in order to gain an understanding of how
decorators work, and for this particular purpose, piling additional
magic on top of decorators is probably not helpful :-)

Regards,
Pat