[C++-sig] Multiple python interpreter contexts

Clay Culver clay at idleengineer.net
Tue Feb 22 23:03:06 CET 2005


Stefan Seefeld wrote:

> It turns out that this does a shallow copy, i.e. pyNamespace2.ptr() == 
> pyNamespace.ptr(),
> and thus modifications to one are immediately visible in the other.
>
> I'm a bit puzzled by this, too, as comments in dict.hpp indicate:
>
>       // dict() -> new empty dictionary.
>       // dict(mapping) -> new dictionary initialized from a mapping 
> object's
>       //     (key, value) pairs.
>       // dict(seq) -> new dictionary initialized as if via:
>
> As there is no mention of the copy constructor I would assume the one 
> that
> applies is 'dict(mapping)', but it doesn't appear to. David ?
>
> In python, you have to explicitely ask for a deep copy by calling the 
> 'copy' method.
> That should work from within C++, too, i.e.
>
> dict pyNamespace2 = pyNamespace.copy() 


Thanks, that did it.  I'm still a bit baffled by that as well.  
Certainly in Python that's how it's done: calling the constructor 
explicitly will perform a deep copy, giving you a new object.

Clay



More information about the Cplusplus-sig mailing list