semi-deepcopy?

Brian Quinlan brian at sweetapp.com
Sun Feb 25 14:31:35 EST 2001


I can't claim to have tried this or completely thought it through, but you
could probably install your own copy handler for undeepcopyable types to
accomplish the behavior that you want i.e.

import copy
import types

copy._deepcopy_dispatch[types.ModuleType] = copy._copy_atomic
# Put all of the other types that you need here...

Normally, I could test this for you but I'm in the process of writing some
patches and I don't have a running copy of Python right now :-)



-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Steven Knight
Sent: Sunday, February 25, 2001 10:31 AM
To: python-list at python.org
Subject: semi-deepcopy?


I need to make a deep copy of an arbitrarily complicated data structure,

e.g., a dictionary where the values are lists of objects that may have
arbitrarily complicated attributes (dictionaries, lists, etc.).

The problem is that elements down in the depths of the structure may be
things like functions or other un-deep-copyable objects.  This makes
copy.deepcopy() throw the exception you'd expect.

What I think I need is a semi-deep (semi-shallow?) copy that performs
a deepcopy when the object supports it, but just copies a reference to
objects that don't.  Sharing references to those objects is fine, but I
do still need to preserve copies of all the other mutable objects in the

structure.

I can't believe I'm the first person to need this functionality, but I
don't see anything like this available.  Am I overlooking some other
way to do what I want, or will I have to roll my own solution here?

        --SK


--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list