pickle.load()在Windows中引发EOFError [英] pickle.load() raising EOFError in Windows
本文介绍了pickle.load()在Windows中引发EOFError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是代码如何使用open(pickle_f,'r')作为fhand:
obj = pickle.load(fhand)
这在Linux系统上工作正常,但在Windows上不行。它显示EOFError。
我必须使用 rb
模式才能在Windows上工作。现在,这不适用于Linux。
为什么会发生这种情况,以及如何解决这个问题? 总是使用 b
open(f,'wb')
用于书写,打开(f,'rb ')
用于阅读)。要修复已有的文件,请使用 dos2unix
来转换换行符。
This is how the code is
with open(pickle_f, 'r') as fhand:
obj = pickle.load(fhand)
This works fine on Linux systems but not on Windows. Its showing EOFError.
I have to use rb
mode to make it work on Windows.. now this isn't working on Linux.
Why this is happening, and how to fix it?
解决方案
Always use b
mode when reading and writing pickles (open(f, 'wb')
for writing, open(f, 'rb')
for reading). To "fix" the file you already have, convert its newlines using dos2unix
.
这篇关于pickle.load()在Windows中引发EOFError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文