Python:IndexError: list index out of range

Python3.x

IndexError: list index out of range

一、范围问题

value无对应的index,造成越界

解决:增加临界判断语句,或者采取+-1

二、

list为空,当list[0]会出现该错误

三、数据问题

如下处理文件时,文件有空行

lenses=[inst.strip().split('\t') for inst in fr.readlines()]

解决:删除空行。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章