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?


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 the bytes vs strings vs unicode problem Grant mentions;
GUIs in either Qt or (especially) GTK; and networking, anything that
uses urllib, urllib2 or related libraries. For those three issues I
usually have to do a lot of porting and debugging by hand, and a lot
of testing afterward because there are always problems that crop up
later upon discovering that the Python3 version of some library is
returning bytes when Python3 wants chars, or some such.

If you don't have automated tests set up, consider writing some now,
before you start porting, with particular emphasis on anything that
gets data from a network or writes it to a file.

        ...Akkana