Python problem

Rhodri James rhodri at wildebst.demon.co.uk
Mon Mar 28 18:18:27 EDT 2011


On Mon, 28 Mar 2011 22:38:29 +0100, John Parker <parkjv1 at gmail.com> wrote:

> infile = open("scores.txt", "r")
> lines = infile.readlines()
> infile.close()
> tokens = lines.split(",")
> names = []
> scores = []

[snippety snip]

> error:
> Traceback (most recent call last):
>   File "Score_8.py", line 38, in <module>
>     tokens = lines.split(",")
> AttributeError: 'list' object has no attribute 'split'
>
> So, what am I doing wrong?

Exactly what the traceback says: you're taking `lines`, the list you  
created of all the lines in the file, and trying to split the list *as a  
whole* on commas.  That doesn't work.  You split strings, not lists.  By  
the looks of it that line is something left over from a previous attempt.   
Just delete it, it's not doing anything useful for you.

-- 
Rhodri James *-* Wildebeest Herder to the Masses



More information about the Python-list mailing list