Created
March 3, 2018 12:05
-
-
Save ansig/99fe8c5960025584343382e86c13c506 to your computer and use it in GitHub Desktop.
Python decorators
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 wrap(element): | |
def decorator(func): | |
@wraps(func) | |
def inner(*args, **kwargs): | |
return "<{0}>{1}</{0}>".format(element, func(*args, **kwargs)) | |
return inner | |
return decorator | |
@wrap("html") | |
@wrap("body") | |
@wrap("p") | |
def say_hello(name): | |
return "Hello {0}!".format(name) | |
print say_hello("Anders") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment