Skip to content

Instantly share code, notes, and snippets.

@sidchilling
Created April 29, 2013 06:39
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/5480034 to your computer and use it in GitHub Desktop.
Save sidchilling/5480034 to your computer and use it in GitHub Desktop.
How to use more than one decorator to decorate a function
# More than one decorator on a function
# A decorator to make text bold
def make_bold(func):
def wrapper_1():
return '<b>%s</b>' %(func())
return wrapper_1
# A decorator to make text italic
def make_italic(func):
def wrapper_2():
return '<i>%s</i>' %(func())
return wrapper_2
@make_bold
@make_italic
def tell():
return 'hello'
print tell()
# Order in which decorators are written MATTERS
@make_italic
@make_bold
def scream():
return 'Oye!'
print scream()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment