[Tutor] IndexError: list index out of range

Dave Angel davea at davea.name
Thu Jun 26 13:13:49 CEST 2014


Myunggyo Lee <somrsaltt at gmail.com> Wrote in message:

You apparently posted this in html, and you tried to attach a data
 file.   Each of those will cause problems for some readers. 
 Please tell your email program to use text mail, and paste in
 your data, don't attach it.

gpdic1={}
while 1:
        line= inf2.readline()
        if not line: break
        lines = line[:-1].split(',')        
             
        hgene = lines[1]
        chr1 = lines[4]
        .....

Apparently,  some of your data has less than two fields in it
 (fields would be a much clearer variable name than lines).  You
 need a test on the len () of lines, probably displaying an error
 if there are less than 9 (or whatever you're expecting). At the
 least you could ignore such lines by doing a continue.

Do you have any plans for dealing with the second line of the
 file? It'll wipe out the dictionary items from the first
 line.

Incidentally,  are you deliberately ignoring the first field on
 the line, lines [0] ?



-- 
DaveA



More information about the Tutor mailing list