Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7468

Re: __dict__ is neato torpedo!

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'memory.': 0.05; 'terry': 0.07; 'mutable': 0.09; 'pm,': 0.10; '>>>': 0.12; 'wrote:': 0.14; 'immutable': 0.16; 'reedy': 0.16; 'thier': 0.16; 'cc:addr:python- list': 0.17; 'cheers,': 0.19; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'values.': 0.23; 'objects': 0.23; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'skip:b 20': 0.23; "doesn't": 0.25; 'received:209.85.161': 0.26; 'pass': 0.27; "i'm": 0.27; 'message- id:@mail.gmail.com': 0.28; 'sat,': 0.29; 'bound': 0.29; 'variables': 0.29; 'class': 0.29; 'cc:addr:python.org': 0.30; 'andrew': 0.32; 'copying': 0.33; 'lists,': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'pretty': 0.37; 'two': 0.37; 'but': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'subject:!': 0.67; '11,': 0.68; 'can:': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=+LPPYskmd6l7yB6p/Sz0e9PdbiSygGS04NSiyVae7M8=; b=Oi+aGE11j8ZPTt6QhycyyPYV4/Qzfk6ta1wUXVOKhOZwVTSex2gwnHtoXWkjzjpdai V1Imx8mVANTA555HTHwmzNT5A5EIJGV0eLqgKYpYq3uwAzA89JGkm8UzAW1dxs3jc+0b 4HOXDvkSQ1NkPtjdM3rmLumT4Ry5AuFrhlyB4=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=BsMsHyL7i8XxZSYtUzZdC+Q/hZPy8aZ6Gl4Tgszz8Ei507IX8r9AOyGwaSLdnGqmCw TPlwtzwe7UBiUEnfQYT08qER9kkwuzuxD3SaK92WDS8VE/d8k8T2nK8aV/fPZ6uX6H+v aQwttqqUMzkRo+saauWEaAJcw2gL1FaYMvhS4=
MIME-Version 1.0
In-Reply-To <4DF422A8.303@gmail.com>
References <4DF41735.60307@gmail.com> <it17a1$vtl$1@dough.gmane.org> <4DF422A8.303@gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Sat, 11 Jun 2011 21:08:40 -0600
Subject Re: __dict__ is neato torpedo!
To Andrew Berg <bahamutzero8825@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc "comp.lang.python" <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.144.1307848151.11593.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 82.94.164.166
X-Trace 1307848151 news.xs4all.nl 49179 [::ffff:82.94.164.166]:49591
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7468

Show key headers only | View raw


On Sat, Jun 11, 2011 at 8:21 PM, Andrew Berg <bahamutzero8825@gmail.com> wrote:
> On 2011.06.11 09:12 PM, Terry Reedy wrote:
>> On 6/11/2011 9:32 PM, Andrew Berg wrote:
>> > I'm pretty happy that I can copy variables and their value from one
>>
>> You are copying names and their associations, but not the objects or
>> thier values.
> Associations? The update() method copies the values; a.val1 and b.val1
> point to two different places in memory.

Incorrect.  The names in b will be bound to the same objects as the
names in a, not to copies of them.  For immutable objects such as
ints, this doesn't matter.  For mutable objects such as lists, it can:

>>> class X(object):
...   pass
...
>>> a = X()
>>> b = X()
>>> a.foo = ['apples']
>>> b.__dict__.update(a.__dict__)
>>> a.foo
['apples']
>>> b.foo
['apples']
>>> a.foo.append('oranges')
>>> a.foo
['apples', 'oranges']
>>> b.foo
['apples', 'oranges']

Cheers,
Ian

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: __dict__ is neato torpedo! Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-11 21:08 -0600

csiph-web