简体   繁体   中英

Python : index out of range

I have a problem, in my code is simply

for i in xrange(len(acid1)):
        j=0
        k=0
        while (j<worksheet.ncols):
            if (acid1[i].lower()==worksheet.row_values(0)[j+1].lower()):
                col1=j+1
                while (k<worksheet.nrows):
                    if (acid2[i].lower()==worksheet.row_values(k+1)[0].lower()):
                        row1=k+1
                        break
                    else:
                        k+=1
                break
            else:
                j+=1

and in line

if (aminokwas1[i].lower()==worksheet.row_values(0)[j+1].lower()):

I get an IndexError: list index out of range. Does anybody know the reason? I don't use any list or anything that I could get out of range. Please help.

When j == worksheet.ncols-1 , it appears that j+1 is not a valid index for worksheet.row_values(0) . Presumably, you make that check for j because the indices for worksheet.row_values are 0 through worksheet.cols - 1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM