Skip to content

Instantly share code, notes, and snippets.

@kivsiak

kivsiak/test.py Secret

Created October 31, 2017 07:16
Show Gist options
  • Save kivsiak/9a2b5965ee3fd40c8c4b072e160a63cf to your computer and use it in GitHub Desktop.
Save kivsiak/9a2b5965ee3fd40c8c4b072e160a63cf to your computer and use it in GitHub Desktop.
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