ClearCode

Decorators with parameters

May 5th, 2022
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. def repetition_decorator(repetitions):
  2.     def decorator(func):
  3.         def wrapper():
  4.             for r in range(repetitions):
  5.                 func()
  6.         return wrapper
  7.     return decorator
  8.  
  9. @repetition_decorator(4)
  10. def func():
  11.     print('Function')
  12.  
  13. #func = repetition_decorator(4)(func)
  14. func()
Advertisement
Add Comment
Please, Sign In to add comment