Created
October 29, 2014 00:45
-
-
Save josePhoenix/80676eac9368d30359de to your computer and use it in GitHub Desktop.
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
| def my_decorator(function_to_decorate): | |
| def new_callable(firstarg, *args, **kwargs): | |
| print "first argument set to", firstarg | |
| return function_to_decorate(firstarg, *args, **kwargs) | |
| new_callable.__doc__ = function_to_decorate.__doc__ | |
| return new_callable | |
| def do_a_thing(foo, bar, baz='quux'): | |
| print "foo is", foo | |
| print "bar is", bar | |
| print "baz is", baz | |
| return 1234 | |
| @my_decorator | |
| def do_a_thing2(foo, bar, baz='quux'): | |
| print "take two:" | |
| print "foo is", foo | |
| print "bar is", bar | |
| print "baz is", baz | |
| return 1234 | |
| do_a_thing('space', 'wow', 'amaze') | |
| do_a_thing2('lol', 'butts', 'omg') | |
| # Output: | |
| # foo is space | |
| # bar is wow | |
| # baz is amaze | |
| # first argument set to lol | |
| # take two: | |
| # foo is lol | |
| # bar is butts | |
| # baz is omg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment