pycon logo

PyCon 2011 Atlanta

March 9th–17th

Log in or Sign Up

Porting to Python 3

log in to bookmark this presentaton

E
Experienced / Talk
March 11th 2:55 p.m. – 3:40 p.m.
A look at the strategies for porting to Python 3, and a quick look of the most common problems.

Abstract

This talk is split into three parts. The first will look at the different options in how to handle Python 3 porting. Do you need to support Python 2, or just port once? Should your code run unmodified or via 2to3, etc. It will in depth take up the benefits and problems with each strategy to let you choose, and also give quick examples of how to port with each strategy.

The second part looks at how you should prepare before porting, and things you can do right now to improve your code and make porting easier, even though you don't plan to port yet.

The third part will take up the most common problems in porting, and how you can solve them.

Choosing a strategy

  • Only support Python 3
  • Separate branches
  • Continuous conversion with 2to3
  • Single code base; no conversion

Preparing for the port

  • Get rid of warnings
  • Use // instead of /
  • Integers don't float
  • Iterator methods
  • Sorting (*)
  • Put an in in it (*)
  • Prepare for bytes
  • Write tests

Common Problems

  • Comparisons
  • Unorderable types
  • Bytes vs Strings vs Unicode (+)
  • Doctests (*)
  • If you don't use 2to3: (*)
    • Stdlib reorg (*)
    • try/except (*)
    • print vs print() (*)
  • C-code (*)

The sections with (*) will be skipped if this gets a short slot. The (+) section will be cut down.