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?


After chickening out a couple of times over the past few years, about eight months ago we migrated our small code base from 2.7.14 to 3.6.5.  Some notes:

On 2.7 we spent a couple of years coding with 3.x in mind, using import from __future__ and coding to Python 3 standards wherever possible.  This greatly reduced the number of changes put into production during cutover and got us used to Python 3.

We used 2to3.py and found that it handled easy cases (print) well and provided a good check on my work when I hand-converted.

The string versus bytes issue was the most difficult.  We receive many files from other financial institutions, who receive some of the data from yet other FIs.  Most of them seem to have little understanding of, or interest in, encodings, and claim to send the files in 'ASCII'.  Python 3 is intolerant of dirty data, whereas previous Pythons let anything go.  I because very familiar with encoding= and errors= on open().  And network protocols want bytes.

I also suggest paying special attention to division (/).  We used the __future__ import to handle this early.

We had some problems installing Python 3.6.5 on Windows Server 2012 that already had 2.7, particularly Registry settings that wound up being wrong.  The problems seemed to occur erratically, so YMMV.  After some trial and error, we chose to leave Python 2.7 installed and install Python launcher for Windows (PyLauncher), to allow for easy fallback (which we never had to do) and because this provided the smoothest install.

We have found Python 3.6.5 to be very reliable on Windows Server 2012.

My next project is to upgrade to Windows Server 2016 and Python 3.7 on a new machine.  We will not be installing Python 2.7 on this machine.

HTH,
  Steve J. Martin