N
nikipore
Hello,
the results of the following code boggle me. i would have expected
that y.data is not affected by setting z.data.
Regards Jan
--code---------------------------------------------
class Test:
def __init__(self, x={}):
self.data = x
#end def
#end class Test
y = Test()
z = Test()
print 'y.data = ',y.data
print 'z.data = ',z.data
z.data['B'] = 2 # this statement also sets y.data
z.data= {'A': 1} # this statement doesn't
print 'y.data = ',y.data
print 'z.data = ',z.data
--code end-------------------------------------------
--output-----------------------------------------------
z.data = {}
y.data = {'B': 2}
z.data = {'A': 1}
the results of the following code boggle me. i would have expected
that y.data is not affected by setting z.data.
Regards Jan
--code---------------------------------------------
class Test:
def __init__(self, x={}):
self.data = x
#end def
#end class Test
y = Test()
z = Test()
print 'y.data = ',y.data
print 'z.data = ',z.data
z.data['B'] = 2 # this statement also sets y.data
z.data= {'A': 1} # this statement doesn't
print 'y.data = ',y.data
print 'z.data = ',z.data
--code end-------------------------------------------
--output-----------------------------------------------
y.data = {}"C:\Program Files\Python25\pythonw" -u "thestrangething.py"
z.data = {}
y.data = {'B': 2}
z.data = {'A': 1}