Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'oct': 0.02; 'operator': 0.04; 'names.': 0.07; 'python': 0.08; 'cc:addr:python-list': 0.15; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '2.7.2': 0.16; '[gcc': 0.16; 'dictionary:': 0.16; 'escribi\xc3\xb3:': 0.16; 'linux2': 0.16; 'subject:copy': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'cc:no real name:2**0': 0.21; 'header :In-Reply-To:1': 0.22; 'wonder': 0.23; 'dictionary': 0.23; 'objects,': 0.23; 'sfxlen:0': 0.23; 'cc:2**0': 0.25; 'cc:addr:python.org': 0.29; 'does': 0.32; 'changes': 0.32; 'header :User-Agent:1': 0.33; 'object': 0.33; 'using': 0.37; 'subject:: ': 0.39; 'change': 0.40; 'type': 0.60; 'more': 0.61; 'eduardo': 0.84; 'subject:write': 0.84 X-IronPort-AV: E=Sophos;i="4.71,504,1320620400"; d="scan'208";a="71026" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Fri, 13 Jan 2012 13:07:05 +0100 From: Jean-Michel Pichavant User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: Eduardo Suarez-Santana Subject: Re: copy on write References: <4F101684.2060502@itccanarias.org> <4F101938.1030806@itccanarias.org> In-Reply-To: <4F101938.1030806@itccanarias.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1326456427 news.xs4all.nl 6882 [2001:888:2000:d::a6]:57820 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18911 Eduardo Suarez-Santana wrote: > 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} > >>> > yes it is. >>> d['x']=r; >>> d['y']=r; means that both d['x'] and d['y'] name the same object r. If you change r, you'll see these changes wheter using d['x'] or d['y']. The operator '=' does not copy objects, it binds an object to a name, and an object can have multiple names. Use the dictionary copy method to copy a dictionary: d['x'] = r.copy() JM