Last active
December 23, 2018 18:56
-
-
Save unanoc/c813f5a47a517ace1edf333c336a83ab to your computer and use it in GitHub Desktop.
python3 decorator
This file contains hidden or 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
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