Does altering a private member decouple the property's value?

Steven D'Aprano steve at
Tue Jun 19 16:23:23 CEST 2007

On Tue, 19 Jun 2007 18:54:41 +1000, Ben Finney wrote:

> "Ethan Kennerly" <kennerly at> writes:
>> I really like properties for readonly attributes,
> Python doesn't have "readonly attributes", and to attempt to use
> properties for that purpose will only lead to confusion.

class Parrot(object):
    def _plumage(self):
        return "Beautiful red plumage"
    plumage = property(_plumage)

>>> parrot = Parrot()
>>> parrot.plumage
'Beautiful red plumage'
>>> parrot.plumage = "Ragged grey feathers"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute

It walks like a read-only attribute, it squawks like a read-only
attribute, but since Python doesn't have read-only attributes, Ben must be
right: using properties to implement read-only attributes will only lead
to confusion.



More information about the Python-list mailing list