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

Alex Martelli aleax at
Tue Jun 19 06:03:21 CEST 2007

Ethan Kennerly <kennerly at> wrote:
> There are a lot of Python mailing lists.  I hope this is an appropriate one
> for a question on properties.

yep, it's a fine one.

> But a gotcha bit me in the behavior of properties that I didn't expect.
> If another function accesses an underlying data member of a property, then
> the data member returned by the property is no longer valid.

You're interpreting wrongly the symptoms you're observing.

> >>> class a_class:

This is ALL of the problem: you're using a legacy (old-style) class, and
properties (particularly setters) don't work right on its instances (and
cannot, for backwards compatibility: legacy classes exist exclusively to
keep backwards compatibility with Python code written many, many years
ago and should be avoided in new code).

Change that one line to

class a_class(object):

and everything else should be fine.  If you want, I can try to explain
the why's and wherefore's of the problem, but to understand it requires
deeper knowledge of Python than you'll need for just about any practical
use of it: just retain the tidbit "NEVER use oldstyle classes" and you
won't need to understand WHY you shouldn't use them:-).


More information about the Python-list mailing list