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


Groups > comp.lang.python > #7464

Re: __dict__ is neato torpedo!

From Terry Reedy <tjreedy@udel.edu>
Subject Re: __dict__ is neato torpedo!
Date 2011-06-11 22:12 -0400
References <4DF41735.60307@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.141.1307844750.11593.python-list@python.org> (permalink)

Show all headers | View raw


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.

> object's namespace to another object's namespace with the same variable
> names automatically:
>
> class simpleObject():
>      pass
>
> a = simpleObject()
> b = simpleObject()
>
> a.val1 = 1
> a.val2 = 2
> b.__dict__.update(a.__dict__)
> a.val1 = 'a'
>
>>>> a.val1
> 'a'
>>>> a.val2
> 2
>>>> b.val1
> 1
>>>> b.val2
> 2


-- 
Terry Jan Reedy

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


Thread

Re: __dict__ is neato torpedo! Terry Reedy <tjreedy@udel.edu> - 2011-06-11 22:12 -0400

csiph-web