Appropriate use of Property()

Gabriel Genellina gagsl-py2 at
Wed Jan 30 07:03:34 CET 2008

On 29 ene, 23:17, noemailplease0... at wrote:

> Property() can be used to rid ourselves of the extra effort of using
> two different methods (getAttrib() setAttrib()) for access of an
> attribute without giving direct access to the attribute, thus making
> it more elegant. So, the outsider using my module accesses the
> attribute with the syntax 'Object.attrib', but since this syntax looks
> as if he is accessing the attribute (rather than through a
> descrtiptor), should we subscribe to this syntax only when the
> attribute is both readable and writable? i.e.,
> if I have an attribute which I strongly believe would always be only
> readable, should I go with the old style 'Object.getAttrib()'?
> Would like to know different perspectives.

I usually implement read only attributes using properties. Sometimes I
may use getXXX() when it is slow to compute and I want to make
explicit that it is a function call. Just my opinion.

Gabriel Genellina

More information about the Python-list mailing list