[Tutor] AttributeError: 'list' object has no attribute 'copy'

Keith Troell ktroell at mac.com
Mon Nov 27 23:29:54 CET 2006


On Nov 27, 2006, at 1:55 PM, Kent Johnson wrote:

> Keith Troell wrote:
>> I'm a rank beginner. I am running Python 2.3.5 on the Terminal of  
>> Mac  OSX.
>> The Tutorial (5.1) mentions list.copy as a list method. When I run
>
> Are you sure? I don't see it here:
> http://www.python.org/doc/2.3.5/tut/ 
> node7.html#SECTION007100000000000000000

Nope, it's not there. Must have had a brain spasm...

>
>> scores = [1, 2, 3]
>> copy = scores.copy ()
>> I get: AttributeError: 'list' object has no attribute 'copy'
>
> You can copy a list with the list() function or by slicing:
> copy = list(scores)
> or
> copy = scores[:]
>

That'll work. Thanks

Keith


More information about the Tutor mailing list