I've spent the last 6 months converting my Python 2.7 scripts over to Python 3. In the nascent days of SDN and Automation that was always one of the first questions asked... To code in Python 2 or Python 3?
There will be some niche projects that keep 2.7 going I suspect, however as this question relates to network automation the answer is clear.
It's time to embrace Python 3.
If you are just getting started, download Python 3 and move along. No need to read this!
For those who started with Python 2, the key impediments are gone. For me Ansible was the last hold out. Starting with Ansible 2.2 (11-01-2016) we saw the effort to move the code base to Python 3. Officially, as of Ansible 2.5.0 (Released 2018-03-22), Python 3 (specifically 3.5 or later) is supported.
All the modules commonly used by network engineers are mature on Python 3.
If the imminent "end of life" of Python 2 is not enough there are some real benefits to moving to Python 3. There are features in Python 3 that will help you if you are beginner:
- f-Strings and no that is not a euphemism - read PEP 498
and features that will help you if you are more advanced:
- dataclasses - PEP 557
just to highlight two of my favorites.
Python 3 also comes with a built-in ipaddress module. I'm a big fan of netaddr which is absolutely available in Python 3 but if you want to share your code and keep dependencies down this is a big plus.