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()]

解決:刪除空行。

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