Jun-15-2021, 12:15 PM
I am new to Python and trying to get my head around Python OOP. I can see that using separate getter and setter is a bad approach and becomes tedious when there are a large amount of user accessible properties. The "proper" way to do this in Python therefore is to use @property and @propertyname.setter decorators.
While I understand the use of @property and @propertyname.setter, the presence of __set__ / __get__ and __setattr__ / __getattr__ have me scratching my head. Why do these even exist if they are not supposed to be used? Also, why there are two pairs and not just one pair of __set__ / __get__.
Finally, do we use the decorator @property or use method Property()? The method needs one to pass the methods that correspond to the getter, setter and deleter for the property
While I understand the use of @property and @propertyname.setter, the presence of __set__ / __get__ and __setattr__ / __getattr__ have me scratching my head. Why do these even exist if they are not supposed to be used? Also, why there are two pairs and not just one pair of __set__ / __get__.
Finally, do we use the decorator @property or use method Property()? The method needs one to pass the methods that correspond to the getter, setter and deleter for the property