[Tutor] Is this correct syntax for what I want?
Alan Gauld
alan.gauld at freenet.co.uk
Sun Jun 25 10:58:42 CEST 2006
> File "C:\Python24\Account Tracker.py", line 10, in load_file
> amount = line.next().strip()
> AttributeError: 'str' object has no attribute 'next'
>
> According to it, the 'str' object has no attribute 'next'. So how
> would I load my file containing my data?
The str object in question is line.
line is a string that you have read from your file.
What exactly do you think the next call would return even
if line had a next method?
I think you may be looking for the split method which will return
a list of fields within the string. You will need to convert the
string data into whatever format you require.
You may find it helpful when debugging these kinds of
problems to insert a few print statements, for example a
print line
at the top of the for loop.
It depends a lot on the format of the data in the file.
Alan G.
More information about the Tutor
mailing list