callcounter Decorator

Decorator method that adds call_count attribute to decorated method. call_count is 0 if method has not been called. call_count increases by 1 each time method is been called.

Note

This decorator needs to be the topmost decorator applied to a method

Example

>>> @callcounter
>>> def foo(msg):
>>>     print(msg)

>>> print("Call Count:", foo.call_count)
0
>>> foo("Hello")
Hello
>>> print("Call Count:", foo.call_count)
1
>>> foo("World")
World
>>> print("Call Count:", foo.call_count)
2