Property Descriptor - Public Getter, Private Setter
jstroud at mbi.ucla.edu
Wed Jul 18 22:51:56 CEST 2007
> Hi all,
> I was looking around the net to figure out how I can use the
> property() descriptor to make a property readable by everyone and only
> settable by the class or any derived classes. Thanks.
Congratulations, you have discovered a principal use of properties--to
restrict access! But how? By the honor system, of course, and some
clever naming techniques and documentation. Below we see all of the
1. clever naming -- our attribute is prepended with an underscore,
signifying its special status as an internal
name and will not be exposed to the API.
2. documentation -- we let our users know about the value property
3. properties -- we make a property named value that is exposed
to the API, but we don't expose _value as it
is not available beyond the class and subclasses
implicitly, by virtue of clever naming (see 1)
Instances of this class are endowed with a 'value' property.
This property is read-only for users of the API. Have a Nice Day.
self._value = None
value = property(get_value)
UCLA-DOE Institute for Genomics and Proteomics
Los Angeles, CA 90095
More information about the Python-list