Last active
December 15, 2015 21:50
-
-
Save Mause/5329055 to your computer and use it in GitHub Desktop.
Decorator demo
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 decorator(*arguments): | |
# this function recieves arguments passed to the decorator | |
def real_decorator(function): | |
# this function recieves the function we are decorating | |
def wrapper(*args, **kwargs): | |
# this function recieves the arguments intended for the function we are decorating | |
# print(args, kwargs) | |
# print(inspect.getargspec(function)) | |
# print('args', arguments) | |
return function(*arguments, *args) | |
return wrapper | |
return real_decorator | |
@decorator(5) | |
def div(x, y): | |
return x / y | |
print(div(10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment