Chapter 22. Moving from Python 2 to Python 3

This chapter covers

  • Using Python 2.6 for preliminary testing
  • Converting using 2to3
  • Testing and common pitfalls
  • Using the same code base for Python 2 and 3

We’ve dealt with only the syntax and features of Python 3.x so far in this book. That was deliberate, because we feel that Python 3.x is a distinct improvement over early versions of Python and it’s where future development should occur. On the other hand, it’s not always possible to make a clean break from the past. For the foreseeable future, many situations will call for dealing with legacy Python 2.x code. This chapter discusses how you can migrate older Python 2.x code to Python 3.x.

22.1. Porting from 2 to 3

Several changes from Python ...

Get The Quick Python Book, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.