Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7463
| Date | 2011-06-11 20:32 -0500 |
|---|---|
| From | Andrew Berg <bahamutzero8825@gmail.com> |
| Subject | __dict__ is neato torpedo! |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.140.1307842367.11593.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
__dict__ is neato torpedo! Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-11 20:32 -0500
Re: __dict__ is neato torpedo! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-12 02:13 +0000
Re: __dict__ is neato torpedo! Andrew Berg <bahamutzero8825@gmail.com> - 2011-06-11 21:28 -0500
Re: __dict__ is neato torpedo! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-12 08:47 +0000
Re: __dict__ is neato torpedo! Hans Mulder <hansmu@xs4all.nl> - 2011-06-12 17:20 +0200
csiph-web