def makebold(fn):
def wrapped():
return "<b>" + fn() + "</b>"
return wrapped
def makeitalic(fn):
def wrapped():
return "<i>" + fn() + "</i>"
return wrapped
@makeitalic
@makebold
def hello():
return "hello world"
print(hello()) ## returns "<b><i>hello world</i></b>"
In this code, why not just define the functions makeitalic() and makebold() and pass in the function hello?
Am I missing something here or are decorators really better for more complicated things?