Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The March To 3
Search
daniellindsley
April 08, 2013
Technology
150
1
Share
The March To 3
The How's and Why's of porting to Python 3.
daniellindsley
April 08, 2013
More Decks by daniellindsley
See All by daniellindsley
The Unenviable Tutorial
daniellindsley
3
140
How (Not) To Build An OSS Community
daniellindsley
1
250
Avoiding The Search Hall Of Shame
daniellindsley
3
430
API Design Tips
daniellindsley
14
3.9k
Building A Python-based Search Engine
daniellindsley
20
2.5k
RESTful APIs with Tastypie
daniellindsley
19
2.9k
Django Boston - 2011
daniellindsley
4
280
Getting The Most Out Of Haystack
daniellindsley
5
250
Other Decks in Technology
See All in Technology
Shiny New Tools Won't Fix Your Problem
trishagee
1
100
ハーネスエンジニアリング入門
hatyibei
0
110
エージェント時代の UIとAPI、CLI戦略
coincheck_recruit
0
150
オライリーイベント登壇資料「鉄リサイクル・産廃業界におけるAI技術実応用のカタチ」
takarasawa_
0
320
ハーネスエンジニアリング入門
knishioka
0
130
アクセシビリティはすべての人のもの
tomokusaba
0
290
Building a Study Buddy AI Agent from Scratch: From Passive Chatbots to Autonomous Systems
itchimonji
0
140
[Scram Fest Niigata2026]Quality as Code〜AIにQAの思考を再現させる試み〜
masamiyajiri
1
260
知ってた?JavaScriptの"正しさ"を検証するテストが5万以上もあること(Test262)
riyaamemiya
1
150
Microsoft 365 / Microsoft 365 Copilot : 自分の状態を確認する「ラベル」について
taichinakamura
0
470
小さいVue.jsを30分で作る
hal_spidernight
0
140
AIと乗り切った1,500ページ超のヘルプサイト基盤刷新とさらにその先の話
mugi_uno
2
310
Featured
See All Featured
Believing is Seeing
oripsolob
1
120
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
350
Bash Introduction
62gerente
615
210k
Darren the Foodie - Storyboard
khoart
PRO
3
3.3k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
260
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Are puppies a ranking factor?
jonoalderson
1
3.4k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.3k
Practical Orchestrator
shlominoach
191
11k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
410
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Transcript
The March To3
Who? • Daniel Lindsley • Pythonista since 2003 • Djangonaut
since 2006 • Author of Tastypie / Haystack / itty / others
None
Your language is...
Your language is... DEAD
Your language is... DEAD ...for small values of “dead”.
None
None
⦸
None
None
⦸
None
is dead;
is dead; Long live !
None
Why port to Python 3?
Active Development Python 2.7.x will only get security updates. No
Python 2.8 ever.
As Fast As 2.7 With 3.3 & it’ll only get
better.
Cleaned Up Syntax We’ll get to some of these in
a bit.
Better String Handling Unicode everywhere.
Stable
None
Changes from 2 to 3 •Removals • Backticks, classic classes
• <>, apply, reduce, dict.has_key • Others
Changes from 2 to 3 •Changed • print is now
print() • next() is now __next__() • Better raise syntax • Metaclasses
Changes from 2 to 3 •Changed (cont.) • Faster Decimal
implementation • Reorganized & spruced up stdlib • Careful with I/O!
Changes from 2 to 3 •New! • Built-in OrderedDict •
String formatting • dict / set comprehensions • Generator delegation via yield from
Changes from 2 to 3 •New! (cont.) • Built-in virtualenv
support! • unittest2 by default! • World domination with importlib
None
“What versions should I support?”
“What versions should I support?” Simple answer: Python 2.6+ &
Python 3.3+
None
“So how do I port?”
IT DEPENDS!
Decide between... • A One-time port • A Combined 2
& 3 codebase ...or...
None
The One-time port
The One-time port • Ensure you have good test coverage
• Use 2to3 to convert the codebase • Run tests & fix until it passes
None
The Combined 2 & 3 codebase
The Combined 2 & 3 codebase • First, you need
a venv: •virtualenv -p python3 env3 •. env3/bin/activate
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!
None
Using six in practice
Demo time.
None
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/
More information • http://www.dabeaz.com/python3io/ MasteringIO.pdf
Thanks! @daniellindsley https://github.com/toastdriven