copy on write

Eduardo Suarez-Santana esuarez at itccanarias.org
Fri Jan 13 06:33:24 EST 2012


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}
 >>>




More information about the Python-list mailing list