scientific-programming-exer.../ex_35.py

22 lines
397 B
Python
Raw Normal View History

2019-01-09 13:19:33 +00:00
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))