Created
October 21, 2019 08:52
-
-
Save tirinox/b6fd34de1b9de229ec2666f160c1ad82 to your computer and use it in GitHub Desktop.
Класс в роли декоратора. Для канала PyWay.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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