Skip to content

Instantly share code, notes, and snippets.

@ycui1
Created September 4, 2020 03:48
Show Gist options
  • Save ycui1/49d2cc1a65063244ec1bef4884ce4a1c to your computer and use it in GitHub Desktop.
Save ycui1/49d2cc1a65063244ec1bef4884ce4a1c to your computer and use it in GitHub Desktop.
>>> 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