[Python-Dev] when is binary mode required for pickle?

Skip Montanaro skip@pobox.com
Wed, 12 Feb 2003 08:59:01 -0600


(I'm really not asking how to use pickle.)

Unused as I am to programming on Windows, it's not clear to me under what
circumstances I might need to open a file in binary mode for Pickle's
consumption.  The reason I ask is that while working on the csv PEP and
module, we had some input complaining about our requirement that CSV files
be opened with the 'b' flag (where it matters).  Andrew mentioned that
Pickle requires files be opened in binary mode.  However, the documentation
doesn't explicitly state this.  Must, for example, a file be opened with the
'b' flag if an ASCII pickle is to be written?  The doc for the Unpickler
class says the file-like object must support both read(n) and readline()
methods.  The requirement for readline() suggests the file be opened in text
mode.

(Maybe this is just a nit with the Pickle docs and I don't know it?)

Skip