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-----------------------------------------------
>"C:\Program Files\Python25\pythonw" -u "thestrangething.py"
y.data =  {}
z.data =  {}
y.data =  {'B': 2}
z.data =  {'A': 1}
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to