22 lines
397 B
Python
22 lines
397 B
Python
|
import time
|
||
|
|
||
|
class counter_of_calls(object):
|
||
|
def __init__(self, f):
|
||
|
self._f = f
|
||
|
self._cnt = 0
|
||
|
|
||
|
def __call__(self, *args, **kwargs):
|
||
|
self._cnt += 1
|
||
|
result = self._f(*args, **kwargs)
|
||
|
print(self._f.__name__, "has been called", self._cnt, "times; last time:", time.time())
|
||
|
return result
|
||
|
|
||
|
|
||
|
@counter_of_calls
|
||
|
def f(x):
|
||
|
return x + 6
|
||
|
|
||
|
if( __name__ == "__main__"):
|
||
|
print(f(3))
|
||
|
print(f(5))
|