Created
July 15, 2015 19:58
-
-
Save wxgeorge/79ff32c7f2fa147451bd to your computer and use it in GitHub Desktop.
python decorators
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
#!/usr/bin/env python | |
def my_decorator(f): | |
def g(x): | |
return f(x, 22) | |
return g | |
def multi_valued_function(arg1, arg2=100): | |
print "multi_valued_function(%s,%s)" % (arg1, arg2) | |
def multi_valued_function_2(arg1, arg2=2234): | |
print "multi_valued_function_2(%s,%s)" % (arg1, arg2) | |
multi_valued_function_2=my_decorator(multi_valued_function_2) | |
@my_decorator | |
def multi_valued_function_3(arg1, arg2=88): | |
print "multi_valued_function_3(%s,%s)" % (arg1, arg2) | |
if __name__ == "__main__": | |
multi_valued_function(1) | |
multi_valued_function_2(2) | |
multi_valued_function_3(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment