pickle format

Anand Pillai pythonguy at Hotpop.com
Wed Oct 15 14:24:48 EDT 2003


Related question. Often I find that when I pickle dictionaries in
pickle's binary format, sometimes the read back fails. So I tend
to use the text pickle format, though this creates larger pickled
files. 

Is there a bug with the binary pickle format?

-Anand

"Terry Reedy" <tjreedy at udel.edu> wrote in message news:<TO6dnS0po_2w4BGiXTWJig at comcast.com>...
> "Jerome Alet" <alet at librelogiciel.com> wrote in message
> news:pan.2003.10.14.22.19.50.444187 at librelogiciel.com...
> > I'd want to pickle a complex Python data structure and save it as
> > a blob in a relationnal database.
> >
> > Now I do that, and I can retrieve it with no problem and then
>  unpickle it.
> >
> > But if I upgrade Python some day, will I still be able to unpickle
>  datas
> > which were pickled with old versions and stored in my database ?
> 
> In short, yes.
> 
> Lib Ref  3.14.2 Data stream format
> 
> There are currently 3 different protocols which can be used for
> pickling.
> 
> Protocol version 0 is the original ASCII protocol and is backwards
> compatible with earlier versions of Python.
> 
> Protocol version 1 is the old binary format which is also compatible
> with earlier versions of Python.
> 
> Protocol version 2 was introduced in Python 2.3. It provides much more
> efficient pickling of new-style classes.
> 
> Refer to PEP 307 for more information.
> -----
> From the PEP:
>  To date, each release of Python has been able to
>     read pickles written by all previous releases.
> 
> Protocol 1 is kept precisely for this reason.  I am sure that Guido
> intends for this to remain true at least thru the 2.x series.  I
> believe this would only change if the Python object system were
> changed enough (in Python 3 or beyond) that unpickling old objects in
> the new system were to make no sense.  If that were to happen, you
> would want to upgrade by addition rather than replacement.
> 
> Terry J. Reedy




More information about the Python-list mailing list