Hey Ian, On Mon, Apr 18, 2011 at 01:07:58PM -0600, Ian Kelly wrote: > In the simple case, just store the state on the wrapper function itself: > > def call_counts(function): > @functools.wraps(function) > def wrapper(*args, **kwargs): > wrapper.num_calls += 1 > return function(*args, **kwargs) > wrapper.num_calls = 0 > return wrapper
Of course! Functions are first-class objects, so I can give them members just as I would do with any other object. I'm still thinking too much C++... > If you want the state to be shared, you should probably store it in an > object and use an instance method as the decorator: Yes, this is the same idea that Wayne came up with. Thank you as well, that helped me understand decorators a lot more. Kind regards, Timo -- http://mail.python.org/mailman/listinfo/python-list