I\'m actually trying doing this in Java, but I\'m in the process of teaching myself python and it made me wonder if there was an easy/clever way to do this with wrappers or
This defines a decorator to do it:
def count_calls(fn): def _counting(*args, **kwargs): _counting.calls += 1 return fn(*args, **kwargs) _counting.calls = 0 return _counting @count_calls def foo(x): return x def bar(y): foo(y) foo(y) bar(1) print foo.calls