-
-
Save kivsiak/9a2b5965ee3fd40c8c4b072e160a63cf 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 addattr(val): | |
def decorator(func): | |
def wrapper(*args, **kwargs): | |
# only use a wrapper if you need extra code to be run here | |
return func(*args, **kwargs) | |
wrapper.attr = val | |
return wrapper | |
return decorator | |
@addattr("xxx") | |
def test(): | |
pass | |
print(test.attr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment