首页 > 解决方案 > 当我的文本文件明显多于 1 行时,为什么会出现此错误?

问题描述

我是 Python 的初学者。我检查了我的文本文件,肯定有超过 1 行,所以我不明白为什么它给了我错误

---> 11     Coachid.append(split[1].rstrip())
  

IndexError: list index out of range

标签: pythonpython-3.xlist

解决方案


如果要遍历文件的行,则必须使用

for line in f.readlines()
    ...

推荐阅读