trouble with copy/deepcopy
Alexander
Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org
Sun May 22 18:04:48 EDT 2005
Привет Mike!
17 мая 2005 в 16:38, Mike Meyer в своем письме к Alexander Zatvornitskiy писал:
MM> Actually, it is shared - but only for reference. If you assign to it,
MM> you'll create an instance variable of the same name. As Peter
MM> explained, if you remove the instance variable, the class variable
MM> becomes visible again. Try this:
py>> class C:
MM> ... q = []
MM> ...
py>> c1 = C()
py>> c2 = C()
py>> c3 = C()
py>> c1.q.append(1)
py>> c2.q.append(2)
py>> c3.q.append(3)
py>> c1.q, c2.q, c3.q
MM> ([1, 2, 3], [1, 2, 3], [1, 2, 3])
py>>
It's true. Surpise!
Hence, every "non-static in c++-meaning" variable must be initialized in
constructor. It seems strange for me.
Thank you for explanation!
Alexander, zatv at bk.ru
More information about the Python-list
mailing list