PyCon Pittsburgh. April 15-23, 2020.

Tutorial: Python 3 Habits: What To Do After You've Upgraded

Presented by:

Trey Hunner

Description

Congratulations on upgrading to Python 3: now that you’ve upgraded, what features should you start embracing and what old habits should you leave behind?

In this tutorial we’ll attempt to take our Python 2-focused brains and reconfigure them to think like Python 3 does. If you feel like you’re writing Python 3 code while still thinking in terms of Python 2, this tutorial is for you.

We’ll over a dozen examples of working Python 2 code and refactor these bits of code to embrace new Python 3 features that are often overlooked after upgrading.

We’ll cover:

  1. Numeric and math changes
  2. String improvements
  3. Distinguishing unicode from bytes
  4. The many new argument packing and unpacking idioms
  5. Changes with classes
  6. Iterators and Lazy Iterables
  7. Improvements to standard library modules
  8. Various Python 3 anti-patterns

You’ll walk out of this tutorial with hands-on Python 3 refactoring experience and more exercises to do when you go home.

Note: This tutorial is for folks who’ve already migrated their Python 2 code to Python 3 and will drop (or have dropped) Python 2 support. We will not cover the upgrading process and we will not cover working with code that works in both Python 2 and Python 3.