看板 Python 關於我們 聯絡資訊
decorator的定義 最基本的應該就是 @g def f(..): 等價於 def f(..): f=g(f) 不過我還是不太清楚,google幾個網站,每一種說法都不同= = 假如我隨便寫了一個 def f2(func): def f3(x): return func(x**2) return f3 @f2 def f1(x): return x 我的想法是 因為f1=f2(f1) 然後因為f2回傳是f3這個函數 所以f1=f3 假如我今天要算f1(20) 就會變成 f1(20)=f3(20) =f1(20**2) =f1(400) =400 跑出來也確實是400 但這樣的想法是正確的嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.42.120.218 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1466941840.A.186.html
MOONY135: f(g(x)) 這種概念可以了解嗎 06/26 22:00
Yshuan: 你可以試著用decorator去做value cache或是time profile 06/26 22:51
uranusjr: 你這樣理解沒有太大問題 06/27 00:11
xdd1524: 感謝 我再琢磨一下 06/27 11:21