Stacking Decorators
You can stack multiple decorators on one function. They apply bottom-up: the closest decorator to the function is applied first.
You can stack multiple decorators on one function. They apply bottom-up: the closest decorator to the function is applied first.
def bold(func):
def wrapper():
return "<b>" + func() + "</b>"
return wrapper
def italic(func):
def wrapper():
return "<i>" + func() + "</i>"
return wrapper
@bold
@italic
def text():
return "Hello"
print(text()) # <b><i>Hello</i></b>
Decorators stack outer-to-inner top-to-bottom: @bold applies after @italic.