cPickle and HIGHEST_PROTOCOL problems
Simon Dahlbacka
sdahlbac at abo.fi
Wed Feb 25 02:36:08 EST 2004
"Tim Peters" <tim.one at comcast.net> wrote in message news:<mailman.35.1077634851.8594.python-list at python.org>...
> [Simon Dahlbacka]
> > I'm trying to cache some information using cPickle
> > and I thought that using cPickle.HIGHEST_PROTOCOL would give me an
> > efficient representation.
> >
> > However,
> >
> > when trying to load the information back I just keep getting a broken
> > pickle with EOF error from cPicle.load(file('myfile.pickle','r'))
> ^^^
>
> Change that 'rb'. Also make sure that the file you write the pickle to is
> opened with 'wb'.
>
> > if I am not using cPickle.HIGHEST_PROTOCOL or -1 or 2 it seems to
> > work nicely, is this a bug or something else? (python 2.3.2 on winxp)
> ^^^^^
>
> Windows distinguishes between text-mode and binary-mode files. Pickles are
> binary data, so files containing pickles must always be opened (for both
> writing and reading) in binary mode. "Mysterious errors" are expected if
> you don't.
..of course! I should have thought of that.. but thanks anyway.
obviously, that fixed the problem, I guess this one goes into the
category of "Stupid user errors" ;)
More information about the Python-list
mailing list