【发布时间】:2016-04-17 03:28:19
【问题描述】:
这是我最近的代码:
highest = {}
def reader():
myfile = open("scores.txt","r")
pre = myfile.readlines()
print(pre)
for line in pre :
print(line)
x = line.split(",")
a = x[0]
b = x[1]
c = len(b)-1
b = b[0:c]
highest[a] = b
这是完整的 Traceback 错误消息:
Traceback (most recent call last):
File "C:/Python34/my boto snaky/snaky.py", line 568, in gameLoop
reader()
File "C:/Python34/my boto snaky/snaky.py", line 531, in reader
b = x[1]
IndexError: list index out of range
【问题讨论】:
-
您在 scores.txt 中的某些行中没有逗号 (',')。另外,使用更好的标题。
-
这真的是你能想到的最具描述性的标题吗?
-
它说错误。 “列表索引超出范围”。您的某些行中没有逗号或缺少数据。
-
实际上他们确实有逗号我认为问题是每个分数之间的空行但我真的不知道如何解决这个问题
-
@AnihsEmma:
"actually they do have commas"和"the issue is the empty lines"是相互排斥的陈述。空行不会有逗号,因此会出现错误。
标签: python