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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -