enhancement request: make py3 read/write py2 pickle format

Zachary Ware zachary.ware+pylist at gmail.com
Tue Jun 9 14:38:11 EDT 2015


On Tue, Jun 9, 2015 at 1:08 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
> One of the most annoying problems with py2/3 interoperability is that the
> pickle formats are not compatible.  There must be many who, like myself,
> often use pickle format for data storage.
>
> It certainly would be a big help if py3 could read/write py2 pickle format.
> You know, backward compatibility?

Uhh...

$ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open('test.pkl', 'wb') as f:
...  pickle.dump({'test': [1, 2, {3}]}, f)
...
>>> with open('test.pkl', 'rb') as f:
...  pickle.load(f)
...
{'test': [1, 2, set([3])]}
>>> ^D
$ python3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open('test.pkl', 'rb') as f:
...  pickle.load(f)
...
{'test': [1, 2, {3}]}
>>> with open('test2.pkl', 'wb') as f:
...  pickle.dump(['test', {2: {3.4}}], f, protocol=2)
...
>>> with open('test2.pkl', 'rb') as f:
...  pickle.load(f)
...
['test', {2: {3.4}}]
>>> ^D
✔ ~
13:35 $ python
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> with open('test2.pkl', 'rb') as f:
...  pickle.load(f)
...
[u'test', {2: set([3.4])}]
>>>

-- 
Zach



More information about the Python-list mailing list