Don't understand behavior; instance form a class in another class' instance

Christian Heimes lists at cheimes.de
Fri Mar 26 00:41:57 CET 2010


Martin P. Hellwig schrieb:
> What I don't understand why in the second test, the last boolean is True 
> instead of (what I expect) False.
> Could somebody enlighten me please as this has bitten me before and I am 
> confused by this behavior.

Hint: TEST2.one is not a reference to TEST2.__instance_one.one. When you
alter TEST2.__instance_one.one you don't magically change TEST2.one,
too. Python doesn't have variables like C pointers. Python's copy by
object (or share by object) behavior can be understand as labels. The
label TEST2.one references the same object as TEST2.__instance_one.one
until you change where the label TEST2.__instance_one.one points to.

Christian




More information about the Python-list mailing list