Re: copy on write

2012-01-13 Thread Eduardo Suarez-Santana

El 13/01/12 11:33, Eduardo Suarez-Santana escribió:

I wonder whether this is normal behaviour.


Even simpler:

$ python
Python 2.7.2 (default, Oct 31 2011, 11:54:55)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> r={'a':1};
>>> d={};
>>> d['x']=r;
>>> d['y']=r;
>>> d['x']['a']=3
>>> d['y']
{'a': 3}
>>>

--
http://mail.python.org/mailman/listinfo/python-list


copy on write

2012-01-13 Thread Eduardo Suarez-Santana

I wonder whether this is normal behaviour.

I would expect equal sign to copy values from right to left. However, it 
seems there is a copy-on-write mechanism that is not working.


Anyone can explain and provide a working example?

Thanks,
-Eduardo

$ python
Python 2.7.2 (default, Oct 31 2011, 11:54:55)
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class n:
... def __init__(self, id, cont):
... self.id = id;
... self.cont = cont;
...
>>> r={'a':1};
>>> d={};
>>> d['x']=r;
>>> d['y']=r;
>>> x1 = n('x',d['x']);
>>> y1 = n('y',d['y']);
>>> x1.cont['a']=2;
>>> y1.cont
{'a': 2}
>>>

--
http://mail.python.org/mailman/listinfo/python-list