Skip to content

Instantly share code, notes, and snippets.

@unanoc
Last active December 23, 2018 18:56
Show Gist options
  • Save unanoc/c813f5a47a517ace1edf333c336a83ab to your computer and use it in GitHub Desktop.
Save unanoc/c813f5a47a517ace1edf333c336a83ab to your computer and use it in GitHub Desktop.
python3 decorator
from functools import wraps
def decorator(argument1=False, argument2=False):
def real_decorator(function):
@wraps(function)
def wrapper(*args, **kwargs):
if argument1 and argument2:
print(" Decorator with arguments!")
result = function(*args, **kwargs)
return result
return wrapper
return real_decorator
@decorator()
def foo():
return 42
@decorator(argument1=True, argument2=True)
def foo1():
return 42
print(foo(), end="")
print(foo1())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment