@
[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