EOFError Ran out of input Python

ε祈祈猫儿з 提交于 2019-12-08 11:37:27

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/45514494/eoferror-ran-out-of-input-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!