Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. calls = {}
  2.  
  3.  
  4. def decorator(func):
  5.     def wrapper():
  6.         if func not in calls:
  7.             calls[func] = 0
  8.         calls[func] += 1
  9.         func()
  10.     return wrapper
  11.  
  12.  
  13. @decorator
  14. def decorated_func_1():
  15.     print('Some prints there')
  16.  
  17.  
  18. @decorator
  19. def decorated_func_2():
  20.     print('And some prints there')
  21.  
  22.  
  23. @decorator
  24. def decorated_func_3():
  25.     print('Сука кто я')
  26.  
  27.  
  28. for each in [decorated_func_1, decorated_func_2, decorated_func_3]:
  29.     each()
  30.  
  31.  
  32. print(calls)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement