[英]pickle.load() raising EOFError in Windows
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. 这在Linux系统上运行良好,但在Windows上却无法运行。 Its showing EOFError.
其显示EOFError。 I have to use
rb
mode to make it work on Windows.. now this isn't working on Linux. 我必须使用
rb
模式才能使其在Windows上运行。现在在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). 读写泡菜时,请始终使用
b
模式( open(f, 'wb')
用于书写, open(f, 'rb')
用于读取)。 To "fix" the file you already have, convert its newlines using dos2unix
. 要“修复”现有文件,请使用
dos2unix
转换其换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.