Does altering a private member decouple the property's value?
Ben Finney
bignose+hates-spam at benfinney.id.au
Tue Jun 19 04:54:41 EDT 2007
"Ethan Kennerly" <kennerly at finegamedesign.com> 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.
> and their ability to make the interface more elegant, by hiding
> uninteresting methods (like dumb get/set accessors).
The best solution to this is not to create get/set accessors at
all. Just define a simple data attribute, name the attribute
logically, and use it normally. When the interface demands something
other than a plain attribute, *then* consider changing it to a
property; but prefer a plain data attribute in the usual case.
> >>> class a_class:
Define your classes as inheriting from 'object', or some other type in
the Python type hierarchy, and properties will work as expected.
class a_class(object):
# foo
--
\ "When I get real bored, I like to drive downtown and get a |
`\ great parking spot, then sit in my car and count how many |
_o__) people ask me if I'm leaving." -- Steven Wright |
Ben Finney
More information about the Python-list
mailing list