pickle's backward compatibility
M.-A. Lemburg
mal at egenix.com
Tue Oct 13 10:48:25 EDT 2009
exarkun at twistedmatrix.com wrote:
> On 03:17 pm, pengyu.ut at gmail.com wrote:
>> Hi,
>>
>> If I define my own class and use pickle to serialize the objects in
>> this class, will the serialized object be successfully read in later
>> version of python.
>>
>> What if I serialize (using pickle) an object of a class defined in
>> python library, will it be successfully read in later version of
>> python?
>
> Sometimes. Sometimes not. Python doesn't really offer any guarantees
> regarding this.
I think this needs to be corrected: the pickle protocol versions are
compatible between Python releases, however, there are two things to
consider:
* The default pickle version sometimes changes between minor
releases.
This is easy to handle, though, since you can provide the pickle
protocol version as parameter.
* The pickle protocol has changed a bit between 2.x and 3.x.
This is mostly due to the fact that Python's native string
format changed to Unicode in 3.x.
http://docs.python.org/library/pickle.html#data-stream-for
Finally, you can register your own pickle functions using the
copy_reg module:
http://docs.python.org/library/copy_reg.html
OTOH, marshal, the more simplistic serialization format used
for basic types and PYC files, does change often and is not
guaranteed to be backwards compatible.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Oct 13 2009)
>>> Python/Zope Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-list
mailing list