EOFError跑出输入Python [英] EOFError Ran out of input Python

查看:60
本文介绍了EOFError跑出输入Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用pickle为我的游戏创建一个保存文件,但是当我尝试提交字典,然后将其取回时,却无法正常工作.

I am trying to use pickle to create a save file for my game, but When I try to submit my dictionary, and then take that information back, but it isn't working.

import pickle
data = {'health':100, 'gold':1560, 'name': 'mariano'}
with open('s.txt','wb') as f:
    pickle.dump(data, f, protocol = 2)

with open('s.txt','rb') as f:
    data = pickle.load(f)

然后,当我运行该代码时,它给了我这个错误

then when I run that code it gives me this error

EOFError: Ran out of input

推荐答案

我弄清楚出了什么问题,或者至少是我如何解决这种情况.您试图使用已经腌制的文件,并且由于运行时出错而将其破坏,所以您要做的就是更改文件名.

I figured out what went wrong, or at least how I fixed the situation. You were trying to use a file that was already pickled, and since it ran with an error it broke it, all you have to do is change the name of the file.

这篇关于EOFError跑出输入Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆