__dict__ is neato torpedo!
Andrew Berg
bahamutzero8825 at gmail.com
Sat Jun 11 21:32:37 EDT 2011
I'm pretty happy that I can copy variables and their value from one
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
The reason I'm posting this is to ask what to watch out for when doing
this. I've seen vague warnings that I don't really understand, and I'm
hoping someone can enlighten me.
More information about the Python-list
mailing list