Elegant copy-by-value

Peter Hansen peter at engcorp.com
Sat Jan 11 22:24:23 EST 2003


Martin Christensen wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> >>>>> "Peter" == Peter Hansen <peter at engcorp.com> writes:
> 
> Peter> Martin Christensen wrote:
> >> For a long time now I've been using copy() or deepcopy(), depending
> >> on the circumstances, from the copy module. Is there no more simple
> >> and elegant way of doing this?
> [...]
> Peter> Have you looked at copy.py?
> 
> Have you looked at the post you replied to? :-)

If you mean, did I misunderstand you, then no, I believe not.

My point was this: if the existing copy.py is that complicated,
but there were a much simpler way, don't you think it would 
already have been implemented?  Or, put another way, having
seen what is in copy.py, I personally do not consider deepcopy
to be "simple" and could well believe there is no chance of
a much simpler, more elegant approach.  The doc-comments in that
module make pretty clear what problems you face if you want
to make deep copy actually work.

I'm actually surprised you have a problem with it.  I've had to
resort to that module only once so far, in two years.  I suppose
if you really have to use it often, it might become a bit of 
an annoyance having to import the module.  Maybe the objects
you are copying can do that for you, and expose a copy method
which makes it appear simple and elegant?

> Peter> If you haven't, take a peek now and then come back and try the
> Peter> question again. ;-)
> 
> That was quick, wasn't it?

It was...

-Peter




More information about the Python-list mailing list