[C++-sig] Multiple python interpreter contexts

Clay Culver clay at idleengineer.net
Wed Feb 23 00:25:46 CET 2005


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



More information about the Cplusplus-sig mailing list