Once upon a time, it was very difficult to:
convert code written in Python 2
write code compatible for py2 and py3
Dependencies + strong language incompatibilities (between Python 2.6 and 3.3).
Now, it much simpler!
main packages all work in Python 3
smaller language incompatibility (between Python 2.7 and >3.4) (for example from __future__ import print_function, division
)
But... still some differences... For example for us in sciences:
division int / int
str are unicode in Python 3 but not in Python 2
Solidify the Python 2 code (write tests!)
Use pyupgrade to modernize the code to Python 2.7 ➡️ test!
Use the automatic tool futurize -w mymodule.py
(provided by future) ➡️ test!
Today, it can make sense to stop supporting Python 2.7 (and even Python 3.5). See https://python3statement.org/.
Main advantage: One can use nice modern features, for example:
f-strings
from pathlib import Path
It can be done automatically with pyupgrade:
find -name "*.py" | xargs pyupgrade --py36-plus