[Python-Dev] docs - Copy

2010-06-24 Thread Rich Healey
http://docs.python.org/library/copy.html

Just near the bottom it reads:

"""Shallow copies of dictionaries can be made using dict.copy(), and
of lists by assigning a slice of the entire list, for example,
copied_list = original_list[:]."""


Surely this is a typo? To my understanding, copied_list =
original_list[:] gives you a clean copy (slicing returns a new
object)

Can this be updated? Or someone explain to me why it's correct?

Cheers

Example:


>>> t = [1, 2, 3]
>>> y = t
>>> u = t[:]
>>> y[1] = "rawr"
>>> t
[1, 'rawr', 3]
>>> u
[1, 2, 3]
>>>
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] docs - Copy

2010-06-24 Thread Rich Healey
On Fri, Jun 25, 2010 at 11:04 AM, Steve Holden  wrote:
> Rich Healey wrote:
>> http://docs.python.org/library/copy.html
>>
>> Just near the bottom it reads:
>>
>> """Shallow copies of dictionaries can be made using dict.copy(), and
>> of lists by assigning a slice of the entire list, for example,
>> copied_list = original_list[:]."""
>>
>>
>> Surely this is a typo? To my understanding, copied_list =
>> original_list[:] gives you a clean copy (slicing returns a new
>> object)
>>
> Yes, but it's a shallow copy: the new object references exactly the same
> objects as the original list (not copies of those objects). A deep copy
> would need to copy any referenced lists, and so on.
>

My apologies guys, I see now.

I will see if I can think of a less ambiguous way to word this and submit a bug.

Thankyou!
___
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com