Created
January 5, 2013 00:44
-
-
Save iKlsR/4458871 to your computer and use it in GitHub Desktop.
decorator example..
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
# A decorator is a function that takes another function object as an argument | |
# and returns said function object as a return value.. | |
def addone(func): | |
"""squares anything passed to it""" | |
def modfunc(n): | |
func(n) | |
print '> and squared it is', n ** 2 | |
return modfunc | |
@addone | |
def printx(x): | |
print '> the original value is', x | |
if __name__ == '__main__': | |
printx(5) | |
print addone.__doc__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
multiline comments are hideous.. <3