[問題] 使用裝飾器註冊函式的疑問

看板Python作者時間6年前 (2018/09/07 06:47), 編輯推噓0(002)
留言2則, 2人參與, 6年前最新討論串1/1
各位大大好, 請教以下程式碼為什麼不管呼叫test多少次 m陣列中都只有註冊到一次 該怎麼理解 謝謝~ m=[] def register(f): m.append(f) return f @register def test(): pass print m # m=[<function test at 0x7f24a6c76488>] test() print m # m=[<function test at 0x7f24a6c76488>] ----- Sent from JPTT on my iPhone -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.73.204.203 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1536302876.A.C14.html

09/07 15:24, 6年前 , 1F
就只有@register那次
09/07 15:24, 1F

09/07 17:33, 6年前 , 2F
呼叫函式不會讓decorator再包ㄧ次
09/07 17:33, 2F
文章代碼(AID): #1RaXySmK (Python)