I usually point out my decorator module
(http://www.phyast.pitt.edu/~micheles/python/decorator.zip) to simplify
decorator usage. In this case you would use it as follows:
from decorator import decorator
@decorator # convert logFunctionCalls into a decorator
def logFunctionCalls(function, *args, **kwargs):
try: # increment the counter
function.counter += 1
except AttributeError: # first call, there is no counter attribute
function.counter = 1
print "Entering function:", function.__name__, function.counter
return function(*args, **kwargs)
@logFunctionCalls
def f():
pass
f()
f()
f()
help(f)
The whole point of the decorator module is that the signature of
the original function is left unchanged (i.e. in this case the
decorated f is still a thunk, not a generic function f(*args, **kw)).
HTH,
Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list