Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Класс в роли декоратора. Для канала PyWay.
# copyright https://t.me/pyway
from functools import wraps
class Repeater:
def __init__(self, n):
self.n = n
def __call__(self, f):
@wraps(f)
def wrapper(*args, **kwargs):
for _ in range(self.n):
f(*args, **kwargs)
return wrapper
@Repeater(3)
def foo():
print('foo')
foo()
# foo
# foo
# foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.