Skip to content

Instantly share code, notes, and snippets.

@Mause
Last active December 15, 2015 21:50
Show Gist options
  • Save Mause/5329055 to your computer and use it in GitHub Desktop.
Save Mause/5329055 to your computer and use it in GitHub Desktop.
Decorator demo
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