pickle format

J

Jerome Alet

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 ?

If not, then is there another module which would be version independant ?

Thanks in advance

Jerome Alet
 
P

Paul Rubin

Jerome Alet said:
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 ?

Yes. At least, that is promised by the documentation.
 
T

Terry Reedy

Jerome Alet said:
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
 
A

Anand Pillai

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
 
P

Paul Rubin

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?

That certainly sounds like a bug, and if you can reproduce it and
attach the data to a bug report, you should do so.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top