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


Groups > comp.lang.python > #7468 > unrolled thread

Re: __dict__ is neato torpedo!

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2011-06-11 21:08 -0600
Last post2011-06-11 21:08 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#7468 — Re: __dict__ is neato torpedo!

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-06-11 21:08 -0600
SubjectRe: __dict__ is neato torpedo!
Message-ID<mailman.144.1307848151.11593.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web