@
[email protected] 未看先推!!這讓我想起,我好像有在 python docs(?) 看到其實"取值"(點操作)並不是直接取,而是會先檢查有沒有定義__get__ 與 __set__,有的話那就用(就是property),沒有的話就直接取,找它的 class member所以,若在 def is_overdue(self) 前加上 @property那麼就可以更 pythonic,把 is_overdue() 函數看成一種變數,應該是這意思囉?感謝大大教學~~雖然總覺得這種"把函數看成變數"的背後機制,似乎跟剛才提的"先檢查有沒有定義__get__與__set__"不太一樣哦哦我在 python docs 看到了!The @property decorator turns the .... method intoa "getter" for a read-only attribute with the samename.
https://i.imgur.com/qmFqRvQ.pnghttps://reurl.cc/drNxOz