Skip to content

Instantly share code, notes, and snippets.

@josePhoenix
Created October 29, 2014 00:45
Show Gist options
  • Select an option

  • Save josePhoenix/80676eac9368d30359de to your computer and use it in GitHub Desktop.

Select an option

Save josePhoenix/80676eac9368d30359de to your computer and use it in GitHub Desktop.
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