Skip to content

Instantly share code, notes, and snippets.

@haoch
Created November 2, 2012 17:35
Show Gist options
  • Save haoch/4002975 to your computer and use it in GitHub Desktop.
Save haoch/4002975 to your computer and use it in GitHub Desktop.
a general python decorator implementation template
def decorator(function):
''' A general decorator implementation
author : cn.haochen@gmail.com '''
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
@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