How to use 2to3 to convert a Python project to Python3

This post is part of a series. This list contains all of the posts:

My blog has been on Python2 for a long time, and today I decided to convert it to Python3.

First step is to install 2to3

pip install 2to3

Then run it on the root directory of my project

2to3 -w blog/

The -w command actually causes the writes to occur. If you want to just get a preview of the changes, just do 2to3 blog.

It's a good idea to go through all the changes. One thing I ran into is that in Python2.7 I always used ex.message in my exceptions. This can be replaced by str(ex).

This post is part of a series. This list contains all of the posts:


Comments

Add Comment

Name

Email

Comment

Are you human? - seven = 0