Created
November 2, 2012 17:35
-
-
Save haoch/4002975 to your computer and use it in GitHub Desktop.
a general python decorator implementation template
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
def decorator(function): | |
''' A general decorator implementation | |
author : [email protected] ''' | |
def wraper(*arg,**kargs): | |
''' actual function logic here ''' | |
# more codes here | |
# ... | |
# if calling original function here then the code defined in original function will run | |
# else just run the code above | |
function(*arg,**kargs) | |
# must return function finally else NoneType object is not callable | |
return wraper |
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
@decorator # used here | |
def original_func(*arg,**kargs): | |
# original function code here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment