windows to linux pickled objects?

Steve Holden sholden at holdenweb.com
Wed Nov 28 08:36:20 EST 2001


"Stephen Boulet" <stephen at theboulets.net> wrote...
> Oleg Broytmann wrote:
>
> > On Tue, Nov 27, 2001 at 11:05:08PM -0600, Stephen Boulet wrote:
> >> I pickled a list in windows but couldn't open it in linux without first
> >> running the handy dos2unix program on it.
> >
> >    Always write binary data to binary files:
> >
> > outfile = open(filename, 'wb')
> > outfile.write(pickle)
> > outfile.close()
> >
> > Oleg.
>
> Thanks to you both for the responses.
>
> But is writing in binary mode supported under linux? The tutorial says:
>
> <<
> On Windows and the Macintosh, 'b' appended to the mode opens the file in
> binary mode
> >>
>
> I tried it on linux and the program did run, but the size of the pickled
> file only went down from 8183905 bytes to 8180057 bytes, and the file
> wasn't binary at all. Maybe the size difference can be explained by the
> lack of carriage returns.  ;)
>
> It would be nice if the binary option worked on linux...
>
>From Python 2.0 Library Reference:
"""A binary format, which is slightly more efficient, can be chosen by
specifying a nonzero (true) value for the bin argument to the Pickler
constructor or the dump() and dumps() functions. The binary format is not
the default because of backwards compatibility with the Python 1.4 pickle
module. In a future version, the default may change to binary. """

So the binary option you require isn't the file open argument (which you
should use as well, because otherwise the file code  might mangle things it
thinks are line endings). It's the binary argument to the pickle methods.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list