Python pickle.load() 在 Windows 中引发 EOFError
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15719930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
pickle.load() raising EOFError in Windows
提问by Surya
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 rbmode to make it work on Windows.. now this isn't working on Linux.
这适用于 Linux 系统,但不适用于 Windows。它显示EOFError。我必须使用rbmode 才能让它在 Windows 上工作......现在这在 Linux 上不起作用。
Why this is happening, and how to fix it?
为什么会发生这种情况,如何解决?
采纳答案by shx2
Always use bmode 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.
b读取和写入泡菜时始终使用模式(open(f, 'wb')用于写入,open(f, 'rb')用于读取)。要“修复”您已有的文件,请使用dos2unix.

