Pickle Problem

Alex Martelli aleax at mac.com
Fri Mar 16 04:13:53 CET 2007


Gary Herron <gherron at islandtraining.com> wrote:
   ...
> fixed, I see another bit of trouble.   The pickle format is a binary 
> format (be default), but you don't open the file in binary mode.   On

Alas, wish it were:-(.

Unfortunately, snipping the right snippet from help(pickle) ...:

"""
     |      The optional protocol argument tells the pickler to use the
     |      given protocol; supported protocols are 0, 1, 2.  The
default
     |      protocol is 0, to be backwards compatible.  (Protocol 0 is
the
     |      only protocol that can be written to a file opened in text
     |      mode and read back successfully.  When using a protocol
higher
     |      than 0, make sure the file is opened in binary mode, both
when
     |      pickling and unpickling.)
     |      
     |      Protocol 1 is more efficient than protocol 0; protocol 2 is
     |      more efficient than protocol 1.
"""

So, by default, you're using the most inefficient protocol... but, you
can write it out to a file opened in text mode and read it back.


Alex



More information about the Python-list mailing list