Skip to content

Instantly share code, notes, and snippets.

@sidchilling
Created April 29, 2013 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidchilling/5480041 to your computer and use it in GitHub Desktop.
Save sidchilling/5480041 to your computer and use it in GitHub Desktop.
script to show how to pass arguments to a decorated function
# Passing arguments to the decorated function
# It's not magic, you just have to let the "wrapper" pass the argument
def a_decorator_passing_arguments(function_to_decorate):
def a_wrapper_accepting_arguments(arg1, arg2):
print 'I got args! Look: %s, %s' %(arg1, arg2)
function_to_decorate(arg1, arg2)
return a_wrapper_accepting_arguments
# Since you are calling the wrapper function which is returned by the decorator, passing arguments
# to the wrapper will let it pass those to the decorated function
@a_decorator_passing_arguments
def print_full_name(first_name, last_name):
print 'My full name is: %s %s' %(first_name, last_name)
print_full_name('Albus', 'Dumbledore')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment