def load():
with open("random_number_highscores.txt","r") as x:
print ("HIGHSCORES")
print ("Least guesses made.")
print (json.load(x))
time.sleep(1)
def save(a):
with open("random_number_highscores.txt", "a") as x:
json.dump(a, x)
print ("saved.")
time.sleep(1)
为什么def加载不起作用。 我尝试用json.dump(str(a),x)保存,但它不起作用或者只是得到错误
答案 0 :(得分:1)
你追加到保存文件,你需要改写:
def save(a):
with open("random_number_highscores.txt", "w") as x:
json.dump(a, x)
json.load()
代码会遇到多个JSON值,并且无法处理文件中的多个。