python 2.6 cPickle.load results in EOFError
Asked Answered
E

1

11

I use cPickle to pickle a list of integers, using HIGHEST_PROTOCOL,

cPickle.dump(l, f, HIGHEST_PROTOCOL)

When I try to unpickle this using the following code, I get an EOFError. I tried 'seeking' to offset 0 before unpickling, but the error persists.

l = cPickle.load(f)

Any ideas?

Eichelberger answered 2/2, 2010 at 20:46 Comment(3)
I just noticed that I am not writing to/ reading from the file in binary mode. Hopefully that will fix this issue.Eichelberger
Obviously I projected that thought to you as I was typing my answer :pRightism
Yes, that's entirely possible :-)Eichelberger
R
20

If you are on windows, make sure you

open(filename, 'wb') # for writing
open(filename, 'rb') # for reading
Rightism answered 2/2, 2010 at 20:49 Comment(2)
Thanks, 7 years later, this is still helpful!. helped me alot ;)Gladstone
Agreed. Just saved me, too.Buxom

© 2022 - 2024 — McMap. All rights reserved.