如何製做功能裝飾器鏈? - How to make a chain of function decorators?

問題:

How can I make two decorators in Python that would do the following? 如何在Python中製做兩個裝飾器,以完成如下工做? app

@makebold
@makeitalic
def say():
   return "Hello"

...which should return: ...應返回: this

"<b><i>Hello</i></b>"

I'm not trying to make HTML this way in a real application - just trying to understand how decorators and decorator chaining works. 我並非想在真實的應用程序中以這種方式製做HTML ,而是試圖瞭解裝飾器和裝飾器連接的工做方式。 spa


解決方案:

參考一: https://stackoom.com/question/36Pu/如何製做功能裝飾器鏈
參考二: https://oldbug.net/q/36Pu/How-to-make-a-chain-of-function-decorators
相關文章
相關標籤/搜索