Shallow vs Deep copies [was Re: python assignment]

Jim Richardson warlock at eskimo.com
Wed Jul 23 13:00:49 EDT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tue, 22 Jul 2003 22:46:56 -0400,
 Tim Peters <tim.one at comcast.net> wrote:
 
> The rule that the object in question is never copied.  There are no
> exceptions to this.  Copying an object requires invoking some method
> of the object, or applying some function to the object.  For example,
> d.copy() returns a (shallow) copy of a dict d, and L[:] returns a
> (shallow) copy of a list L.


To clarify for me please.

A shallow copy of an object, returns an object that contains references
to objects within the copied object, yes? 

so a list consisting of [1,2,a,"a"] when copied shallowly, will return
exactly that, but when copied deeply, will reture [1,2,"whatever a
points to","a"] yes? 

If I understand the above correctly.... how deep does a deep copy go?
can you vary the depth? Or is it binary, shallow or deep? 

Thanks.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/Hr9Bd90bcYOAWPYRAnaYAKDDRFGR6FG3ytgN2dwf7w1shDND3QCgs33B
8jNxKhsF1Ti7bkbPzbCxEx4=
=6a1K
-----END PGP SIGNATURE-----

-- 
Jim Richardson         http://www.eskimo.com/~warlock

Linux, because eventually, you grow up enough to be trusted with a fork()




More information about the Python-list mailing list