""" This is a simple example of the use of Python's decorator syntax. To keep it simple, trace does not work with functions called with keyword arguments. The output could be improved, also. """ def trace(f): def new_f(*args): print 'Entering %s%s' % (f.__name__, args) result = f(*args) print 'Exiting %s%s with %s' % (f.__name__, args, result) return result return new_f @trace def sum(n, m): return n + m @trace def fact(n): return 1 if n<2 else n * fact(n-1)