Definition of "property"

Terry Reedy tjreedy at udel.edu
Sun May 30 16:22:14 EDT 2021


On 5/30/2021 12:57 PM, Irv Kalb wrote:
> I am doing some writing (for an upcoming book on OOP), and I'm a little stuck.
> 
> I understand what a "property" is, how it is used and the benefits, but apparently my explanation hasn't made the light bulb go on for my editor.  The editor is asking for a definition of property.  I've looked at many articles on line and a number of books, and I haven't found an appropriate one yet.
> 
> I have written some good examples of how it works, but I agree that a definition up front would be helpful.  I have tried a number of times, but my attempts to define it have not been clear.  Perhaps the best I've found so far is from the Python documentation:
> 
> A property object has getter, setter, and deleter methods usable as decorators that create a copy of the property with the corresponding accessor function set to the decorated function.
> 
> But I'm hoping that someone here can give me a more concise (one or two sentence) definition of the word "property".
> 
> (I would like to avoid going through the whole derivation with the property function, as that would distract from the points that I am trying to make.)

 From a user viewpoint, which is likely close to that of the editor, a 
property is a possibly dynamic class attribute managed by up to 3 hidden 
functions.

A user only needs to know that an attribute is a property when it has 
otherwise surprising dynamic behavior.  For instance, if 'time.now != 
time.now', or if 'time.now = something; print(time.now)' does not print 
'something'.

Note: at least one person says a property *pretends* to be an attribute. 
  I think a more useful view is that it *is* an attribute with a 
particular behind-the-scene implementation.  When a normal attribute is 
converted to a 'property', it effectively still is an attribute.  The 
syntax manipulating the attribute remains the same.  If one can set, 
get, and delete something dotted notation, it is an attribute.

-- 
Terry Jan Reedy



More information about the Python-list mailing list