Created
December 4, 2017 03:06
-
-
Save petronetto/20455a844620a980a94c184bec59d827 to your computer and use it in GitHub Desktop.
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
def ntimes(n): | |
def inner(f): | |
def wrapper(*args, **kwargs): | |
for _ in range(n): | |
print('Running: {.__name__}'.format(f)) | |
rv = f(*args, **kwargs) | |
return rv | |
return wrapper | |
return inner | |
@ntimes(2) | |
def add(x, y=10): | |
return x + y | |
@ntimes(5) | |
def sub(x, y): | |
return x - y | |
print('Add:', add(10)) | |
print('Sub:', sub(10, 5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment