Why do descriptors (and thus properties) only work on attributes.

Antoon Pardon apardon at forel.vub.ac.be
Mon Feb 28 05:11:24 EST 2005


Op 2005-02-28, Diez B. Roggisch schreef <deetsNOSPAM at web.de>:
> Antoon Pardon wrote:
>
>> Op 2005-02-28, Paul Rubin schreef <http>:
>>> Antoon Pardon <apardon at 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?
>> 
>> 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.
>
> 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?

Lazy evaluation where the value of something is calculated the first
time it is needed but accessed from some storage if it is needed again.

-- 
Antoon Pardon



More information about the Python-list mailing list