zeldor.biz

Linux, programming and more

Copyright © 2023
Log in

Python 2 to 3 migration

April 11, 2019 by Igor Drobot Leave a Comment

pythonclock.org is a pretty simple countdown for the end of Python 2.
The End Of Life, sunset date for Python 2.7 is officially announced to January 1, 2020.

It’s not a 1 April fool joke and not a really something new.
Python 3, a major, backwards-incompatible release, was released on December 3, 2008. [2]
So lets say, it was pretty clear who has not switched to Python 3 version,
it’s your own fault.

This a simple dive in for converting Python code from version 2 to Python 3.


2to3 is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code.

pip3 install 2to3

Basic usage, the converted Python3 code will shown on stdout:

2to3 example.py

Inline converting with auto backup creation example.py.bak:

2to3 -w example.py

From now, worry only about supporting your Python 3 code ;)
This tools will help you to make sure, you code will be runable and readable.

pip3 install pylint
pip3 install pycodestyle
pip3 install autopep8

Run code verifications for your code:

pylint example.py
pycodestyle example.py
autopep8 example.py

Sources:
[1] Porting Python 2 Code to Python 3
[2] What’s New In Python 3

Filed Under: Linux Tagged With: pip3, python migration, python2, python3

Categories

Archives

Tags

apache2 Apple arduino ARM Automation backup bash Cisco Cluster Corosync Database Debian Debian squeeze DIY DNS Fedora FTP Fun Icinga Ipv6 KVM Linux LVM MAC OS X Monitoring MySQL Nagios Nginx openSUSE OpenVPN PHP Proxy Python python3 qemu RAID rsync Samba security ssh Ubuntu virtualization Windows Windows 7 Wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *