python - 当我的文本文件明显多于 1 行时,为什么会出现此错误?
问题描述
我是 Python 的初学者。我检查了我的文本文件,肯定有超过 1 行,所以我不明白为什么它给了我错误
---> 11 Coachid.append(split[1].rstrip())
IndexError: list index out of range
解决方案
如果要遍历文件的行,则必须使用
for line in f.readlines()
...
推荐阅读
- javascript - 链接到动态页面时出现下一个js错误
- sql - 两次加入一个表并计算记录
- react-native - 使用 editable=true 和 dataDetectorTypes 反应原生 TextInput
- python - 排序python列表基于另一个列表
- python - 迭代时更新 Dataframe - Python
- java - 线程可以中断自己吗?
- python - 遍历列表(浮点数不可下标)
- extendscript - 如何在 Scriptui (Extendscript) 中在按钮标题中使用下标或上标?
- elixir - Elixir 中的尾调用优化
- python - 还有其他方法可以共享/运行代码吗?