Feb. 23, 2005
8:25 a.m.
Stefan Seefeld wrote:
Python:
d = dict(x.__dict__) # copies x.__dict__ d['whatever'] # modifies the copy
"
This is confusing. May be I'm reading the above not correctly, but in my interpretation 'making a copy' means making a deep copy, and 'modifies the copy' implies the original is unchanged. However:
class A: ... def foo(self): return 42 ... d = A.__dict__ print id(d), id(A.__dict__) -1208268764 -1208268764
Following the code above that though:
class A: ... def foo(self): ... return 42 ... d = dict( A.__dict__ ) print id(d), id( A.__dict__ ) 10356464 10357184
Which is a deep copy. The C++ doesn't seem to do the same thing when you pass a value into dict( ). Clay