4

Is there an existing implementation of an iterative version of deepcopy for Python 2.5.2? The deepcopy method available from the copy module is recursive and fails on large trees. I am not in a position where we can safely increase the stack limit at runtime.

EDIT

I did track this down:

http://code.activestate.com/recipes/302535/

I haven't tested it, but it looks like it has potential.

4

2 回答 2

1

I'm not sure this would make sense. Isn't the whole point of deepcopy that each object will ask its children to copy themselves?

Presumably you know exactly what kind of object you're copying and what its children look like as well, so if I were you, I'd just write my own function to copy it. Shouldn't be too hard.

于 2009-03-05T23:11:45.877 回答
0

也许它可以与Stackless Python一起工作

于 2009-03-06T01:08:35.237 回答