Created
April 29, 2013 06:40
-
-
Save sidchilling/5480041 to your computer and use it in GitHub Desktop.
script to show how to pass arguments to a decorated function
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
# 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