[Tutor] How do I fix the following error? Code and error messagesupplied.

Alan G alan.gauld at freenet.co.uk
Thu Aug 4 09:05:27 CEST 2005


> How do I fix the following error:
Traceback (most recent call last):
  File "D:\Python24\password.py", line 51, in load_file
    [site,ID,passcard] = string.split(in_line,",")
  File "D:\Python24\lib\string.py", line 292, in split
    return s.split(sep, maxsplit)
AttributeError: 'list' object has no attribute 'split'

So it tells us that s is a list which has no split attribute.
Looking at the line in your code that suggests that in_line is a list.

def load_file(sitelist,filename):
    in_file = open(filename,"r")
    while 1:
        in_line = in_file.readlines()

And so it is, readlines returns all of the lines in the file as a 
list.

        if in_line == "":
            break
BTW
The above section of code would be much easier if you used a for loop:

    for line in in_file:

that's it, that's all you need to process each line of the file in 
turn.

        in_line = in_line[:-1]

This strange line returns a list containing the last line of the file.
The rest of the file having been thrown away! But its still a list.


        [site,ID,passcard] = string.split(in_line,",")

So we get a problem here.

        sitelist[site] = sitelist

You need to convert in_line to a string. (Or more exactly extract
the string from within in_line). The answer to most of your questions
is given inthe error messages Nathan, just look at what it tells
you and the approximate location of the error in your code.

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld





More information about the Tutor mailing list