Skip to content

Instantly share code, notes, and snippets.

@tirinox
Created October 21, 2019 08:52
Show Gist options
  • Save tirinox/b6fd34de1b9de229ec2666f160c1ad82 to your computer and use it in GitHub Desktop.
Save tirinox/b6fd34de1b9de229ec2666f160c1ad82 to your computer and use it in GitHub Desktop.
Класс в роли декоратора. Для канала 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