__dict__ is neato torpedo!
Terry Reedy
tjreedy at udel.edu
Sat Jun 11 22:12:19 EDT 2011
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
More information about the Python-list
mailing list