Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #18911
| 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 | <prvs=3520c88ba=jeanmichel@sequans.com> |
| 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 <jeanmichel@sequans.com> |
| User-Agent | Mozilla-Thunderbird 2.0.0.24 (X11/20100328) |
| MIME-Version | 1.0 |
| To | Eduardo Suarez-Santana <esuarez@itccanarias.org> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4710.1326456427.27778.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: copy on write Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-01-13 13:07 +0100
csiph-web