fork download
  1. class counter:
  2. def __init__(self,fn):
  3. self.count=0
  4. self.fn=fn
  5.  
  6. def __call__(self,*args):
  7. self.count=self.count+1
  8. return self.fn(*args)
  9.  
  10. def counter(self):
  11. return self.count
  12.  
  13. @counter
  14. def fun(a, b):
  15. return a * 1 + b
  16.  
  17. print(fun.counter())
  18. res = sum(fun(i, i + 1) for i in range(5))
  19. print(fun.counter(), res)
Success #stdin #stdout 0.02s 9080KB
stdin
Standard input is empty
stdout
0
5 25