我已经盯着这段代码看了一天半了,谷歌没有帮助。对我来说它看起来不错,但它不断抛出错误。
该程序运行一个测验并在最后收集一个分数,如下所示:
print("That was the last question!")
print("Your final score is", score)
name = input('What is the players name? ')
highsc = highscore(score, name)
我知道分数有效,但是当我输入球员姓名时,它会尝试运行我的高分定义:
def highscore(score, name):
entry = (score, name)
hs_data = open('tops.dat', 'rb')
highsc = pickle.load(hs_data)
hs_data.close()
hs_data = open('tops.dat', 'ab')
highsc.append(entry)
highsc.sort(reverse=True)
highsc = highsc[:5]
pickle.dump(highsc, hs_data)
hs_data.close()
return highsc
但是我每次都会遇到相同的错误:-
File "C:\Users\Desktop\py3e_source\py3e_source\trivia_challenge.py", line 55, in highscore
highsc = pickle.load(hs_data)
File "C:\Python31\lib\pickle.py", line 1365, in load
encoding=encoding, errors=errors).load()
EOFError
请帮忙。