trouble with copy/deepcopy
Alexander
Alexander_Zatvornitskiy at p131.f3.n5025.z2.fidonet.org
Mon May 16 17:11:37 EDT 2005
Привет Marc!
16 мая 2005 в 22:18, Marc 'BlackJack' Rintsch в своем письме к All писал:
MR> That clears only one dictionary at class level. Which is visible on
MR> both instances.
MR> class Distribution:
MR> def __init__(self):
MR> self.__gr_on_transp = dict()
MR> self.__ostatok_m = dict()
MR> ...
MR> This creates *instance variables* which should be deepcopied
MR> without problems.
Hmm. I don't find definition of "class variable" in manual. I try to test it on
such a simple test and find that such variable is NOT shared between copies:
class C:
q=int()
c1=C()
c2=C()
c1.q=5
c2.q=10
print c1.q
#5
print c2.q
#10
After deepcopy of c1 or c2, all classes have own copy of q. After replacing
integer q on dictionary, results are the same. There is an error?
Alexander, zatv at bk.ru
More information about the Python-list
mailing list