Created
October 19, 2011 02:12
-
-
Save zeeshanlakhani/1297319 to your computer and use it in GitHub Desktop.
Make a Decorator Python
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
#simple decorators concept from... | |
#http://stackoverflow.com/questions/739654/understanding-python-decorators | |
def makebold(fn): | |
def wrapped(): | |
return "<b>" + fn() + "</b>" | |
return wrapped | |
def makeitalic(fn): | |
def wrapped(): | |
return "<i>" + fn() + "</i>" | |
return wrapped | |
@makebold | |
@makeitalic | |
def hello(): | |
return "hello world" | |
print hello() ## returns <b><i>hello world</i></b> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment