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

Dieter Maurer dieter at handshake.de
Thu May 6 15:08:11 EDT 2004


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.

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


-- 
Dieter



More information about the ZODB-Dev mailing list