Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
>>> class Repeat:
... def __init__(self, n):
... self.n = n
...
... def __call__(self, func):
... def repeater(*args, **kwargs):
... for _ in range(self.n):
... func(*args, **kwargs)
...
... return repeater
...
... @Repeat(n=2)
... def morning_greet(person):
... print(f"Good Morning, {person}!")
...
... @Repeat(n=3)
... def afternoon_greet(person):
... print(f"Good Afternoon, {person}!")
...
... morning_greet("Jason")
... afternoon_greet("Kelly")
...
Good Morning, Jason!
Good Morning, Jason!
Good Afternoon, Kelly!
Good Afternoon, Kelly!
Good Afternoon, Kelly!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment