Surya Kasturi
Surya Kasturi

Reputation: 4776

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. 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?

Upvotes: 14

Views: 24279

Answers (1)

shx2
shx2

Reputation: 64318

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.

Upvotes: 25

Related Questions