Pickle compatibility between Python 2.7 and python 3.2

Jesus Cea jcea at jcea.es
Mon Feb 21 18:27:02 EST 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have 10MB pickled structure generated in Python 2.7. I only use basic
types (no clases) like sets, dictionaries, lists, strings, etc.

The pickle stores a lot of strings. Some of them should be "bytes",
while other should be "unicode". My idea is to import ALL the strings as
bytes in Python 3.2 and navigate the data structure to convert the
appropiate values to unicode, in a one-time operation (I version the
structure, so I can know if this conversion is already done, simply
storing a new version value).

But I get this error:

"""
Python 3.2 (r32:88445, Feb 21 2011, 13:34:07)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> f=open("file.pickle", mode="rb").read()
>>> len(f)
9847316
>>> b=pickle.loads(f,encoding="latin1")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: operation forbidden on released memoryview object
"""

I use the encoding "latin1" for transparent byte/unicode conversion (do
not touch the values!).

This seems to be a bug in Python 3.2. Any suggestion?.

PS: The bytestream is protocol 2.

- -- 
Jesus Cea Avion                         _/_/      _/_/_/        _/_/_/
jcea at jcea.es - http://www.jcea.es/     _/_/    _/_/  _/_/    _/_/  _/_/
jabber / xmpp:jcea at jabber.org         _/_/    _/_/          _/_/_/_/_/
.                              _/_/  _/_/    _/_/          _/_/  _/_/
"Things are not so easy"      _/_/  _/_/    _/_/  _/_/    _/_/  _/_/
"My name is Dump, Core Dump"   _/_/_/        _/_/_/      _/_/  _/_/
"El amor es poner tu felicidad en la felicidad de otro" - Leibniz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQCVAwUBTWL0xplgi5GaxT1NAQL+NwQAmIXK5er0rJysH0KudC05ys8DxGpswsez
oEv60rAVMOImF+2ftizNudvB8FaCoQqEDeshJ3oPN/AmnZ2vqlrMLJdO5hjG88pS
W39+qEpRz0JNz2RUdLOpXdLqm9aU56KUqq9F0P8nqI02djsSXTYTmmUHZd37GhPt
pV1l7+1cpb0=
=pjS+
-----END PGP SIGNATURE-----



More information about the Python-list mailing list