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

作者: peter9s3b   2018-09-07 14:47:53
各位大大好,
請教以下程式碼為什麼不管呼叫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>]
作者: djshen (djshen)   2018-09-07 15:24:00
就只有@register那次
作者: thefattiger (LT)   2018-09-07 17:33:00
呼叫函式不會讓decorator再包ㄧ次

Links booklink

Contact Us: admin [ a t ] ucptt.com