Python problem

Peter Pearson ppearson at nowhere.invalid
Mon Mar 28 18:11:45 EDT 2011


On Mon, 28 Mar 2011 11:38:29 -1000, John Parker <parkjv1 at gmail.com> wrote:
[snip]
> I have written the following code so far but get an error.
>
> infile = open("scores.txt", "r")
> lines = infile.readlines()
> infile.close()
> tokens = lines.split(",")

[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?

infile.readlines returns a list of strings, each string being
one line of the input file.  Being a list, it doesn't have
a "split" attribute.  Strings have a "split" attribute.

Did you intend to split just one of the input strings?




More information about the Python-list mailing list