Decorator question
Michele Simionato
michele.simionato at gmail.com
Wed May 23 10:40:37 EDT 2007
If you are using Python 2.5, you can use functools.update_wrapper to
simplify your life. For instance
from functools import update_wrapper # requires Python 2.5
def trace(func):
def wrapper(*args,**kw):
print 'calling %s with args %s' % (func.__name__,args)
return func(*args,**kw)
return update_wrapper(wrapper,func)
class P(object):
@classmethod
@trace
def c(cls):
print cls
p =P()
p.c()
Also, you can have a look to my own decorator module:
http://www.phyast.pitt.edu/~micheles/python/decorator.zip
HTH,
Michele Simionato
More information about the Python-list
mailing list