thinkings on shallow copy
Steven Taschuk
staschuk at telusplanet.net
Thu Jun 19 11:26:20 EDT 2003
Quoth Kendear:
> i was just looking at docstrings and saw the one
> for copy.__doc__ regarding copy.copy():
>
> > - A shallow copy constructs a new compound object and then (to the
> > extent possible) inserts *the same objects* into in that the
> > original contains.
>
> I wonder if it is actually to insert *the same object references*
> into the new compound object...
Sort of. Better: "inserts references to the same objects".
(Saying that the references are the same suggests, erroneously,
that changing one reference would change the other:
a = [1, 2, 3]
b = copy.copy(a)
a[0] = 'q'
print b[0] # does not print 'q'
)
The notion of references is so pervasive in Python that these docs
shouldn't need to emphasize it, imo.
[...]
> so shallow copy constructs a new compound object
> and copies the references in the source compound
> object to the new compound object, is that correct?
Correct.
--
Steven Taschuk "[W]e must be very careful when we give advice
staschuk at telusplanet.net to younger people: sometimes they follow it!"
-- "The Humble Programmer", Edsger Dijkstra
More information about the Python-list
mailing list