Created
March 18, 2015 18:07
-
-
Save samueljackson92/ed5e51e75477247c7482 to your computer and use it in GitHub Desktop.
Functools demo
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
"""Showing the cool stuff which functools does""" | |
import functools | |
def print_shit(f): | |
"""Because Sam, you need to learn why decorators are sexy. | |
Plus, functool.wraps() is a _very_ important tool, yo | |
""" | |
@functools.wraps(f) | |
def inner(*args, **kwargs): | |
print "Hello Sam, do you like cats?" | |
ret = f(*args, **kwargs) | |
print "Good bye Sam" | |
return ret | |
return inner | |
def broken_shit(f): | |
"""Because Sam, you need to learn why decorators are sexy. | |
Plus, functool.wraps() is a _very_ important tool, yo | |
""" | |
def inner(*args, **kwargs): | |
print "Hello Sam, do you like cats?" | |
ret = f(*args, **kwargs) | |
print "Good bye Sam" | |
return ret | |
return inner | |
@print_shit | |
def main(): | |
"""A found docstring""" | |
pass | |
@broken_shit | |
def broken_main(): | |
"""A lost docstring.""" | |
pass | |
if __name__ == "__main__": | |
main() | |
broken_main() | |
print "" | |
print "Main: {}".format(main.__doc__) | |
print "Broken Main: {}".format(broken_main.__doc__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment