为什么描述符(以及属性)仅适用于属性。 [英] Why do descriptors (and thus properties) only work on attributes.

查看:65
本文介绍了为什么描述符(以及属性)仅适用于属性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释为什么描述符仅在它们是对象或类的属性

时才起作用。我认为,如果对象本身就是
而不是另一个对象的属性,那么使用描述符可能会产生很多有趣的事情。 br />

那么以这种方式限制这个功能的原因是什么?


-

Antoon Pardon

Can anyone explain why descriptors only work when they are an attribute
to an object or class. I think a lot of interesting things one can
do with descriptors would be just as interesting if the object stood
on itself instead of being an attribute to an other object.

So what are the reasons for limiting this feature in such a way?

--
Antoon Pardon

推荐答案

Antoon Pardon< ap ***** @ forel.vub.ac.be>写道:
Antoon Pardon <ap*****@forel.vub.ac.be> writes:
任何人都可以解释为什么描述符仅在它们是对象或类的属性时才起作用。我认为如果对象站在自身而不是属于另一个对象的属性,那么可以用描述符做很多有趣的事情就会很有趣。
Can anyone explain why descriptors only work when they are an attribute
to an object or class. I think a lot of interesting things one can
do with descriptors would be just as interesting if the object stood
on itself instead of being an attribute to an other object.




如何运作?



How would that work?


Op 2005-02-28,Paul Rubin schreef< http>:
Op 2005-02-28, Paul Rubin schreef <http>:
Antoon Pardon< ap ***** @ forel.vub.ac.be>写道:
Antoon Pardon <ap*****@forel.vub.ac.be> writes:
任何人都可以解释为什么描述符仅在它们是对象或类的属性时才起作用。我认为如果对象站在自身而不是属于另一个对象的属性,那么可以用描述符做很多有趣的事情就会很有趣。
Can anyone explain why descriptors only work when they are an attribute
to an object or class. I think a lot of interesting things one can
do with descriptors would be just as interesting if the object stood
on itself instead of being an attribute to an other object.


<这是怎么回事?



How would that work?




好​​AFAIU描述符是一个对象,至少有一个方法来自
__get __,__ set__或__del__。我不明白为什么隐含地调用这些方法时,如果它们是自主的,那么这些方法会比它们属性更加困难。


-

Antoon Pardon



Well AFAIU a descriptor is an object with at least one method out of
__get__, __set__ or __del__. I don see why implicitly calling one
of these methods would be any more difficult when they are autonomous
objects than when they are attributes.

--
Antoon Pardon


Antoon Pardon写道:
Antoon Pardon wrote:
Op 2005- 02-28,Paul Rubin schreef< http>:
Op 2005-02-28, Paul Rubin schreef <http>:
Antoon Pardon< ap ***** @ forel.vub.ac.be>写道:
Antoon Pardon <ap*****@forel.vub.ac.be> writes:
任何人都可以解释为什么描述符仅在它们是对象或类的属性时才起作用。我认为如果对象站在自身而不是属于另一个对象的属性,那么可以用描述符做很多有趣的事情就会很有趣。
Can anyone explain why descriptors only work when they are an attribute
to an object or class. I think a lot of interesting things one can
do with descriptors would be just as interesting if the object stood
on itself instead of being an attribute to an other object.


<这是怎么回事?



How would that work?



AFAIU描述符是一个对象,至少有一个方法来自__get __,__ set__或__del__。我不明白为什么隐含地调用这些方法中的一个当它们是自主的对象时比它们属性时更难。



Well AFAIU a descriptor is an object with at least one method out of
__get__, __set__ or __del__. I don see why implicitly calling one
of these methods would be any more difficult when they are autonomous
objects than when they are attributes.




我仍然没有看到它应该如何用于很多有趣的

的东西。你能为这些有趣的东西提供一些例子吗?


-

问候,


Diez B. Roggisch



I still don''t see how that is supposed to work for "a lot of interesting
things". Can you provide examples for one of these interesting things?

--
Regards,

Diez B. Roggisch


这篇关于为什么描述符(以及属性)仅适用于属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆