Steven Knight knight at
Sun Feb 25 13:30:59 EST 2001

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


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?


More information about the Python-list mailing list