[ZODB-Dev] Re: copy.copy on Persistent object (ExtensionClass) fails.

Casey Duncan casey at zope.com
Thu May 6 16:12:35 EDT 2004


On Thu, 6 May 2004 21:08:11 +0200
Dieter Maurer <dieter at handshake.de> wrote:

> Syver Enstad wrote at 2004-5-6 00:31 +0200:
> >How do I copy a Persistent object (I am using ZODB 3.2).
> 
> You can use pickling to get an unsharing deep copy.
> 
> 	from cPickle import loads, dumps
> 
> 	copy = loads(dumps(obj,1))
> 
> Be warned, however, that this uses undocumented implementation
> details of "dumps" that are not garanteed to always work
> and may change across Python distributions.

Can you elaborate on that?

> For a more reliable alternative, you can look how Zope
> implements its "OFS.CopySupport.CopySource._getCopy()" method.

I believe it uses ZODB's export/import mechanism. If you can peel away
the Zopeisms, it's probably a good way to go.

-Casey




More information about the ZODB-Dev mailing list