Slide 1

Slide 1 text

The March To3

Slide 2

Slide 2 text

Who? • Daniel Lindsley • Pythonista since 2003 • Djangonaut since 2006 • Author of Tastypie / Haystack / itty / others

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Your language is...

Slide 5

Slide 5 text

Your language is... DEAD

Slide 6

Slide 6 text

Your language is... DEAD ...for small values of “dead”.

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

is dead;

Slide 15

Slide 15 text

is dead; Long live !

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Why port to Python 3?

Slide 18

Slide 18 text

Active Development Python 2.7.x will only get security updates. No Python 2.8 ever.

Slide 19

Slide 19 text

As Fast As 2.7 With 3.3 & it’ll only get better.

Slide 20

Slide 20 text

Cleaned Up Syntax We’ll get to some of these in a bit.

Slide 21

Slide 21 text

Better String Handling Unicode everywhere.

Slide 22

Slide 22 text

Stable

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Changes from 2 to 3 •Removals • Backticks, classic classes • <>, apply, reduce, dict.has_key • Others

Slide 25

Slide 25 text

Changes from 2 to 3 •Changed • print is now print() • next() is now __next__() • Better raise syntax • Metaclasses

Slide 26

Slide 26 text

Changes from 2 to 3 •Changed (cont.) • Faster Decimal implementation • Reorganized & spruced up stdlib • Careful with I/O!

Slide 27

Slide 27 text

Changes from 2 to 3 •New! • Built-in OrderedDict • String formatting • dict / set comprehensions • Generator delegation via yield from

Slide 28

Slide 28 text

Changes from 2 to 3 •New! (cont.) • Built-in virtualenv support! • unittest2 by default! • World domination with importlib

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

“What versions should I support?”

Slide 31

Slide 31 text

“What versions should I support?” Simple answer: Python 2.6+ & Python 3.3+

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

“So how do I port?”

Slide 34

Slide 34 text

IT DEPENDS!

Slide 35

Slide 35 text

Decide between... • A One-time port • A Combined 2 & 3 codebase ...or...

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

The One-time port

Slide 38

Slide 38 text

The One-time port • Ensure you have good test coverage • Use 2to3 to convert the codebase • Run tests & fix until it passes

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

The Combined 2 & 3 codebase

Slide 41

Slide 41 text

The Combined 2 & 3 codebase • First, you need a venv: •virtualenv -p python3 env3 •. env3/bin/activate

Slide 42

Slide 42 text

The Combined 2 & 3 codebase • Ensure you have good test coverage • Require six as a dependency • Use six to patch over the differences • Run tests in Py3 & fix until it passes... • ...then run tests in Py2 & fix until it passes!

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Using six in practice

Slide 45

Slide 45 text

Demo time.

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

More information • http://pyvideo.org/video/1730/python-33- trust-me-its-better-than-27 • http://pyvideo.org/video/1787/porting- django-apps-to-python-3 • http://pyvideo.org/video/1704/why-you- should-use-python-3-for-text-processing • http://pythonhosted.org/six/

Slide 48

Slide 48 text

More information • http://www.dabeaz.com/python3io/ MasteringIO.pdf

Slide 49

Slide 49 text

Thanks! @daniellindsley https://github.com/toastdriven