>And, of course, Guido will probably post a much more elegant and
>efficient solution:-)
No, I won't, since the problem is impossible to solve in full
generality.
A "simple" problems is how to treat objects that contain references to
themselves (maybe indirectly). This can be solved by keeping a list
of all references encountered during the copying. But what to do with
instances of user-defined classes, or worse, instances of opaque
built-in data types -- the latter may be defined by dynamically loaded
extension modules written in C, so you can't know in advance how to
handle them all.
Even types that you do know about beforehand can cause complications
-- how would you define a deep copy on an open file or a window object?
I must say that I can't remember that the general version of the
problem has ever come up in all the tens of thousands of lines of
Python code I've written -- one level of copying is usually
sufficient. Lou, were you thinking of a particular application or
were you just trying to find out what the limits of the language are?
--Guido van Rossum, CWI, Amsterdam <guido@cwi.nl>
"Many of my best friends are lumberjacks and only a few of them are
transvestites"