[Python-porting] pickle data

Gregory P. Smith greg at krypto.org
Mon Dec 22 17:50:30 CET 2014


Or update your Python 2 code to save its data in a proper well defined
language agnostic portable data format instead of a pickle. Pickles are
definitely a problem. My own advice is to never use them for anything you
don't mind throwing away (ie: simple caches).

On Tue Dec 16 2014 at 5:32:55 PM Benjamin Peterson <benjamin at python.org>
wrote:

>
>
> On Tue, Dec 16, 2014, at 20:26, Barry Warsaw wrote:
> > Here's an interesting situation I am faced with as I port Mailman 3 to
> > Python
> > 3.  I haven't seen any other discussion of it, so I thought I'd post here
> > for
> > posterity.
> >
> > Let's say you have a pickle created in Python 2 that is to be read in
> > Python
> > 3.  In Mailman 2, persistent mailing list data is stored in pickles.
> >
> > It seems like both Python 2 types (unicode and str/bytes) get unpickled
> > as
> > Python 3 str types.
>
> You can change this by passing encoding="bytes" to pickle.loads. See
> https://docs.python.org/3/library/pickle.html#pickle.load
>
> >
> > * Python 2 unicode should unpickle as Python 3 str
> > * In Python 2, bytes are just an alias for str
> > * There's no way to know the intent of whether Python 2 "bytes" should be
> >   unpickled as Python 3 bytes or str.
>
> Yeah, this is problematic. Probably the best you can do is unpickle
> everything with bytes then manually decode actual string things into
> str.
> _______________________________________________
> Python-porting mailing list
> Python-porting at python.org
> https://mail.python.org/mailman/listinfo/python-porting
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-porting/attachments/20141222/0e46664c/attachment.html>


More information about the Python-porting mailing list