[问题] @property

楼主: tsaiminghan (tsaiminghan)   2022-08-16 23:22:29
我在看@propery的实现方法
https://stackoverflow.com/questions/17330160/how-does-the-property-decorator-work-in-python
大约可以了解descriptor object的用法。文中有提到下面Property的class内容
https://docs.python.org/3/howto/descriptor.html#properties
不过我还有一个疑问,如下面的程式码,@x.setter的x是哪来的︊我知道这个x是跟函式名一样,但是就property的class,看不出来
@x.setter的x是怎么产生的
作者: lycantrope (阿宽)   2022-08-17 10:33:00
x在第一个property产生了
作者: a129924 (EnKimi)   2022-08-18 00:44:00
就是你要设定property的参数 例如name 那就是@name.setter
作者: GALINE (天真可爱CQD)   2022-08-26 12:43:00
在 @x.setter 前一行打 print(x) 会看到他是个property object其实也可以自己实作看看 https://tinyurl.com/mww2u9vh虽然这版本应该跟 python 本身的实现差很多
楼主: tsaiminghan (tsaiminghan)   2022-08-31 16:31:00
谢谢

Links booklink

Contact Us: admin [ a t ] ucptt.com