More assignment/copy novice confusion

Arthur Siegel ajs at ix.netcom.com
Sun Dec 2 10:22:00 EST 2001


Given a class:

>>> class  p:
             def __init__(self,a):
                 self.a=a
Then -

>>> m=p([1,2,3])
>>> r=m
>>> m.a=([1,2,4])
>>> m.a
[1, 2, 4]
>>> r.a
[1, 2, 4]

clear enough.

But -

>>> m=p([1,2,3])
>>> r=p([])
>>> r.a=m.a
>>> m.a=[1,2,4]
>>> m.a
[1, 2, 4]
>>> r.a
[1, 2, 3]


And -

>>> m=p([1,2,3])
>>> r=m
>>> r.a=m.a
>>> m.a=[1,2,4]
>>> m.a
[1, 2, 4]
>>> r.a
[1, 2, 4]


I know this isn't the tutorial list.  

But - on the theory that my confusion 
on these kinds of issues is widely shared 
among novices - I thought it worth bringing
up for discussion, clarification.

Is anything here affected by the new style classes?

Art






More information about the Python-list mailing list