osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What is your experience porting Python 2.7.x scripts to Python 3.x?


On Wed, Jan 23, 2019 at 9:43 AM Akkana Peck <akkana at shallowsky.com> wrote:
>
> Grant Edwards writes:
> > On 2019-01-22, Schachner, Joseph <Joseph.Schachner at Teledyne.com> wrote:
> >
> > > For anyone who has moved a substantial bunch of Python 2 to Python
> > > 3, can you please reply with your experience?
> >
> > If you used bytes (or raw binary strings) at all (e.g. for doing
> > things like network or serial protocols) you're in for a lot of pain.
> >
> > Everything else is pretty minor.
>
> 2to3 handles most porting issues nicely. The three pain points I've
> hit are ...... networking, anything that
> uses urllib, urllib2 or related libraries.

For this last one, I would recommend first porting your code to using
'requests' as much as possible, if you aren't already. The requests
API is consistent across Py2 and Py3, and then all you need urllib
itself for is a handful of utility functions like urllib.parse, which
I believe 2to3 can handle.

Yes, requests is third-party. But it's such a good library that I
recommend it fully any time you aren't utterly unable to use non-core
libraries.

ChrisA