python - How to make a chain of function decorators? -
how can make 2 decorators in python following?
@makebold @makeitalic def say(): return "hello"
...which should return:
"<b><i>hello</i></b>"
i'm not trying make html
way in real application - trying understand how decorators , decorator chaining works.
check out the documentation see how decorators work. here asked for:
def makebold(fn): def wrapped(): return "<b>" + fn() + "</b>" return wrapped def makeitalic(fn): def wrapped(): return "<i>" + fn() + "</i>" return wrapped @makebold @makeitalic def hello(): return "hello world" print hello() ## returns "<b><i>hello world</i></b>"
Comments
Post a Comment