Re: Definition of "property"
Greg Ewing ezt írta (időpont: 2021. jún. 2., Sze, 4:01): > On 1/06/21 7:01 am, Alan Gauld wrote: > > That was the point, the OP said it was a book about OOP. > > Not a book about "OOP in Python". > > In that case it would be best to avoid the word, or give > a definition of the way he's using it, making it clear > that it's not a universal definition. Python's definition > is somewhat unusual, and so would not be appropriate. > > -- > Greg > > -- > https://mail.python.org/mailman/listinfo/python-list > Hi, I think in OOP point of view one can write that property is the python implementation of the OOP concepts: Encapsulation and Information hiding Some explanation for beginners on these paradigms: https://stackify.com/oop-concept-for-beginners-what-is-encapsulation/ BR, George -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 1/06/21 7:01 am, Alan Gauld wrote: That was the point, the OP said it was a book about OOP. Not a book about "OOP in Python". In that case it would be best to avoid the word, or give a definition of the way he's using it, making it clear that it's not a universal definition. Python's definition is somewhat unusual, and so would not be appropriate. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 31/05/2021 15:59, Dennis Lee Bieber wrote: > On Sun, 30 May 2021 21:20:24 +0100, Alan Gauld via Python-list > declaimed the following: > >> On 30/05/2021 17:57, Irv Kalb wrote: >>> I am doing some writing (for an upcoming book on OOP), and I'm a little >>> stuck. >> >> Oh dear, that's one of myt hot buttons I'm afraid! >> I hope it really is about OOP and not about classes. Classes >> are such a minor part of OOP that it is depressing how many > To me, OOP tends to be language specific... OOP is supposed to be a programming paradigm in the same way that Functional or Logic programming are paradigms. Its all about how you organise your code. It should be based on message passing between autonomous agents(objects). Classes etc are language constructs aimed at making OOP easier, but they are not OOP. It's very easy to build a class/object based program that is not in any way OOP (in fact I'd go as far as to say the majority of such programs today come into that category). It's also possible (but difficult!) to build an OOP program without classes. Incidentally, I'm not arguing that classes should not be used in imperative programming, they can be very powerful there too. Just that using classes is not necessarily OOP. > Finding books on OOAD -- which should be language agnostic -- is > more difficult, and tend to turn into books about how to use > UML rather than how to analyze/design using OO. That's a fairly modern phenomenon. Most of the early books about OOAD were language agnostic - even when they used a language for demonstration purposes. Books like Grady Booch's classic OOAD, or Peter Coad's series with Ed Yourdon. The so-called method wars. They all had their own methodology, but mostly that was just diagrammatic variances. The underlying techniques and resultant structures were the same. (And hence the move to UML, which is just a notation - an extremely useful one, although often abused through over zealous application.) Even Rumbaugh's OMT book was meant to be general OOD, although IMHO it was the least OO of all of them being heavily based on data modelling. Sadly, there are very few books today that even attempt to describe the difference between OOP and the more common procedural programming paradigm. Discussions of OOP have degenerated into discussions about OOPL features rather than how to build worlds of objects passing messages to each other. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 6/1/21, Jon Ribbens via Python-list wrote: > > I already answered that in the post you are responding to, but you > snipped it: You can tell something's definitely not a data attribute > if you have to put brackets after its name to call it as a method to > invoke its function or retrieve the value it returns. I prefer to use the generic term "computed attribute", which doesn't interfere with the use of "data" in Python's concept of a data descriptor and instance data. All descriptors are accessed without calling them. Usually a non-data descriptor returns a bound callable object, such as a method. But it can return anything. For example, take the following P descriptor type: class P: def __get__(self, obj, cls): if obj is not None: return 42 return self class C: p = P() obj = C() >>> obj.p 42 The P type doesn't implement __set__ or __delete__, so it's not a data descriptor. This means we can set instance data `p` that overrides the computed attribute. For example: >>> obj.p = 21 >>> vars(obj) {'p': 21} >>> obj.p 21 >>> del obj.p >>> obj.p 42 -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 2021-06-01, Greg Ewing wrote: > On 1/06/21 2:34 am, Jon Ribbens wrote: >> From the outside, it's just a *data* attribute. Which, from the inside, >> it isn't. Hence "pretending". > > But what is it about the external appearance that would make > you think it's a data attribute, rather than some other kind > of attribute? I already answered that in the post you are responding to, but you snipped it: You can tell something's definitely not a data attribute if you have to put brackets after its name to call it as a method to invoke its function or retrieve the value it returns. > (I'm assuming that by "data attribute" you mean a piece of > data that's stored directly in the object. If you mean > something else, we might be talking at cross purposes.) I mean it in the sense it is used by the Python documentation. -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 1/06/21 2:34 am, Jon Ribbens wrote: From the outside, it's just a *data* attribute. Which, from the inside, it isn't. Hence "pretending". But what is it about the external appearance that would make you think it's a data attribute, rather than some other kind of attribute? (I'm assuming that by "data attribute" you mean a piece of data that's stored directly in the object. If you mean something else, we might be talking at cross purposes.) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 31/05/2021 01:24, Greg Ewing wrote: > On 31/05/21 8:20 am, Alan Gauld wrote: >> >> That's a very Pythonic description. > > If it's a book about Python, it needs to be. The word "property" > has a very specialised meaning in Python. > > In some other languages it's used the way we use "attribute" in > Python. So a Python-specific definition is necessarily going > to be very different from a generic one. That was the point, the OP said it was a book about OOP. Not a book about "OOP in Python". The two are not synonymous. If we go back to the very beginnings of OOP, properties were defined as the publicly available state variables of the object. (Some others favoured using "properties" to describe the entire set of messages to which an object could respond). In classification theory they are defined as "the essential characteristics of an object that identify it with a class" Some theorists also insist that such properties be immutable after instantiation of the object. The first could be considered quite close to what Python does(or allows you to do) but the second is quite different! Although properties can be used to create a form of immutablity. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 2021-05-31, Greg Ewing wrote: > On 31/05/21 9:13 am, Jon Ribbens wrote: >> No, I said it pretends to be a *data* attribute. > > I don't think it's pretending to be anything. From the outside, > it's just an attribute. >From the outside, it's just a *data* attribute. Which, from the inside, it isn't. Hence "pretending". > Data attributes are more common than non-data attributes, so > we tend to assume that an attribute is a data attribute until > told otherwise. But that's just our psychological bias, not > because of any pretence on the part of properties. None of that is true. You can tell something's definitely not a data attribute if you have to put brackets after its name to call it as a method to invoke its function or retrieve the value it returns. Accessing a data attribtue is efficient and has no side effects, unless someone's doing some unusual and probably inadvisable hackery behind the scenes. Calling a method can do literally anything. > Also, there's a sense in which *all* attributes are properties. > At the lowest level, all attribute accesses end up calling > a method. It's just that in most cases the method is implemented > in C and it looks up a value in the object's dict. Sure, if we take the "lowest level" and pretend there are no higher-level structures it's all just electrons doing apparently random things and there's nothing more to be said about it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
> On May 30, 2021, at 10:15 AM, Jon Ribbens via Python-list > wrote: > > On 2021-05-30, Irv Kalb wrote: >> 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. > > A property is an attribute of a class that pretends to be a data > attribute but in fact causes methods to be called when it is > accessed. Thank you to everyone who made suggestions of a definition of a property. I will go with a definition based on this one from Jon R, with the clarification from Terry R. Yes, the upcoming book is on object-oriented programing using Python, and goes into detail about the concepts behind OOP. The unique approach is that I use pygame and explain how to build a number of user interface "widgets" (like buttons, text input and output boxes, draggers, etc.) to show the fundamentals of OOP in a highly visible way. I use these widgets to implement a number of small games that also incorporate some additional classes like timers, animation, etc. Irv -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 31/05/21 9:13 am, Jon Ribbens wrote: No, I said it pretends to be a *data* attribute. I don't think it's pretending to be anything. From the outside, it's just an attribute. Data attributes are more common than non-data attributes, so we tend to assume that an attribute is a data attribute until told otherwise. But that's just our psychological bias, not because of any pretence on the part of properties. Also, there's a sense in which *all* attributes are properties. At the lowest level, all attribute accesses end up calling a method. It's just that in most cases the method is implemented in C and it looks up a value in the object's dict. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 31/05/21 4:57 am, Irv Kalb wrote: 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. That's not a definition of a property -- it's talking about a mechanism that provides one way of creating a property, using decorators. DON'T quote that as a definition! -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 31/05/21 8:20 am, Alan Gauld wrote: That's a very Pythonic description. If it's a book about Python, it needs to be. The word "property" has a very specialised meaning in Python. In some other languages it's used the way we use "attribute" in Python. So a Python-specific definition is necessarily going to be very different from a generic one. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 30/05/2021 23:57, Mike Dewhirst wrote: > > A property is an object method masquerading as a cachable object attribute Or a group of methods perhaps? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 2021-05-30, Terry Reedy wrote: > Note: at least one person says a property *pretends* to be an attribute. No, I said it pretends to be a *data* attribute. It is effectively several methods in a trenchcoat pretending to be a variable. -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 5/30/21, Ethan Furman wrote: > > > Properties are a special kind of attribute. Basically, when Python > encounters the following code: > > > > spam = SomeObject() > > print(spam.eggs) > > > > it looks up eggs in spam, and then examines eggs to see if it has a > __get__, __set__, or __delete__ > > method — if it does, it's a property. The above is not quite right. Having a __get__ method is not sufficient. In the quoted example, the `eggs` attribute of the SomeObject type has to be a data descriptor type, which means it defines a __set__ and/or __delete__ method. A computed attribute that's implemented by a data descriptor type cannot be overridden by an instance attribute of the same name. In contrast, a non-data descriptor type only defines a __get__ method (e.g. the `function` type is a non-data descriptor). A computed attribute that's implemented by a non-data descriptor type will be overridden by an instance attribute of the same name. The two common data descriptor types are `property` and `member_descriptor` (from __slots__), but creating custom data descriptor types is easy to implement. See "customizing attribute access" in the data model documentation, and in particular "implementing descriptors" and "invoking descriptors": https://docs.python.org/3/reference/datamodel.html#customizing-attribute-access -- https://mail.python.org/mailman/listinfo/python-list
RE: Definition of "property"
You guys are all very knowledgeable but he is asking what to say to an EDITOR who clearly may know little or nothing about computers and thinks python is a snake and not a language and may need to be spoken to in his own language which understands other forms of abstraction better. So, just for humor, give him the communist version of property. Property is owned by the state and is a reflection of such a state. It is hidden and can only be accessed through apparatchiks working for the state. You tell them what you want and they go invisibly and do whatever they want which may even include manipulating what lies underneath the capitalist concept of a property. This is called a Setter as in you set it up and they knock it down. Now when you ask for some kind of report of what the property is now like, that is a getter as you get what they feel like giving. And, yes, if you ask them to delete it, if it indeed still exists (or ever existed) they may tell you it was deleted and then take it for themselves! So, a property is something abstract that you are not allowed to see or in any way interact with except through layers that hide things and take it on faith that it is being done in a way that is good for you, OR ELSE. Now would your editor understand that? Disclaimer: I repeat, humor. Others have provided decent answers. But, they were not necessarily born in a communist country which your parents luckily took you out of in time! -Original Message- From: Python-list On Behalf Of Alan Gauld via Python-list Sent: Sunday, May 30, 2021 4:20 PM To: python-list@python.org Subject: Re: Definition of "property" On 30/05/2021 17:57, Irv Kalb wrote: > I am doing some writing (for an upcoming book on OOP), and I'm a little stuck. Oh dear, that's one of myt hot buttons I'm afraid! I hope it really is about OOP and not about classes. Classes are such a minor part of OOP that it is depressing how many books and articles focus on them to the exclusion of all else that make up the OOP paradigm! Anyway, rant over... > I understand what a "property" is, how it is used and the benefits, Do you? What is that based on? Is it how properties are used in OOP? Or how they are used in Python? Is your book truly about OOP or how Python does OOP (very different things!) How do python properties compare to properties in other languages like Object Pascal(aka Delphi) and Eiffel for example? Which of these 3 options most closely models the pure OOP concept of a property? > definition of property. In OOP or in Python? Or both? > 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. That's a very Pythonic description. > (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.) Which are? Hopefully, about abstraction of data and function/methods therby encouraging polymorphic representations of program structures, which is the essence of OOP. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On Sun, May 30, 2021 at 9:57 AM 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.) > > Thanks in advance, > I tend to think of properties as dynamic attributes. And I'm not their biggest fan. I don't like having a look where a class and its parent classes are defined to tell if something that looks like an attribute, really is an attribute. I understand that exposing an attribute as part of a public API is faster, and the ability to make them dynamic later keeps you from painting yourself in a corner, but I'd rather just slow down computation a little than end up with a little greater maintenance burden. -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 31/05/2021 2:57 am, 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". A property is an object method masquerading as a cachable object attribute (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.) Thanks in advance, Irv -- Signed email is an absolute defence against phishing. This email has been signed with my private key. If you import my public key you can automatically decrypt my signature and be sure it came from me. Just ask and I'll send it to you. Your email software can handle signing. OpenPGP_signature Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 31/05/2021 04.57, 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.) +1 Everything in Python is an object. Objects can perform an almost-unlimited range of services, fulfilling a wide variety of purposes. A property constrains the object to more focussed functionality ... eg an integer which may not hold a negative value, a string which may not be empty... -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 30/05/2021 17:57, Irv Kalb wrote: > I am doing some writing (for an upcoming book on OOP), and I'm a little > stuck. Oh dear, that's one of myt hot buttons I'm afraid! I hope it really is about OOP and not about classes. Classes are such a minor part of OOP that it is depressing how many books and articles focus on them to the exclusion of all else that make up the OOP paradigm! Anyway, rant over... > I understand what a "property" is, how it is used and the benefits, Do you? What is that based on? Is it how properties are used in OOP? Or how they are used in Python? Is your book truly about OOP or how Python does OOP (very different things!) How do python properties compare to properties in other languages like Object Pascal(aka Delphi) and Eiffel for example? Which of these 3 options most closely models the pure OOP concept of a property? > definition of property. In OOP or in Python? Or both? > 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. That's a very Pythonic description. > (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.) Which are? Hopefully, about abstraction of data and function/methods therby encouraging polymorphic representations of program structures, which is the essence of OOP. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
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 -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 2021-05-30, Irv Kalb wrote: > 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. A property is an attribute of a class that pretends to be a data attribute but in fact causes methods to be called when it is accessed. -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On 5/30/21 9:57 AM, Irv Kalb wrote: > 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. My answer from Stackoverflow [1]: > Properties are a special kind of attribute. Basically, when Python encounters the following code: > > spam = SomeObject() > print(spam.eggs) > > it looks up eggs in spam, and then examines eggs to see if it has a __get__, __set__, or __delete__ > method — if it does, it's a property. If it is a property, instead of just returning the eggs object > (as it would for any other attribute) it will call the __get__ method (since we were doing lookup) > and return whatever that method returns. Feel free to use that however you like. :) -- ~Ethan~ [1] https://stackoverflow.com/a/7377013/208880 -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
> On 30 May 2021, at 17:57, 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.) How does this sound? An object is the combination of behaviour and state. Classes define the object. Methods allow the control of behaviour. Properties hold the state. The use of getter functions allows a property's value to be calculated. The use of setting functions allows a property change to update the state an object. The python property mechanism allows the getting and setter to be hidden from the API as that the user of the object can see the propery as a simple attribute of an object. Barry > > Thanks in advance, > > Irv > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Definition of "property"
On Mon, May 31, 2021 at 2:58 AM 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". > A property is an attribute with customized get/set behaviour. It lets you change what normally happens when you say "print(thing.attribute)" or "thing.attribute = spam". Personally, I wouldn't bother mentioning deletion in the opening definition, for brevity's sake, but it'll be there when you go into detail. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Definition of "property"
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.) Thanks in advance, Irv -- https://mail.python.org/mailman/listinfo/python-list