Skip to content

Instantly share code, notes, and snippets.



Last active Jan 22, 2020
What would you like to do?
class CallLimitException(Exception):
def call_limit(limit=10):
def deco(wrapped):
nonlocal limit
i = 0
def wrapper(*args, **kwargs):
nonlocal i
i += 1
if i > limit:
raise CallLimitException(i)
return wrapped(*args, **kwargs)
return wrapper
return deco
def f(x):
return x
for j in range(1, 20):
print(f'{j}: {f(j)}')
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.