O'Reilly logo
live online training icon Live Online training

Pythonic Code Refactoring Session

Writing Python Code Like a Native

Topic: Programming
Trey Hunner

What makes code Pythonic? Which programming "best practices" are universal and which are unique to Python? In this 2-hour course, we'll refactor code as a group, converting programs with unidiomatic Python code to programs that embrace the full power of Python. Together, we'll practice identifying Python features that can help us improve our code readability and clarity.

What you'll learn-and how you can apply it

By the end of this live, hands-on, online course, you’ll understand:

  • Where to embrace common Python-specific syntaxes
  • How to idiomatically loop over multiple things at once, loop in reverse, and loop with indexes
  • How the Python standard library can help you avoid reinventing the wheel

And you’ll be able to:

  • Identify places in your code where tuple unpacking should be used
  • Identify places where comprehensions should be used
  • Make your existing Python code feel a bit more like a Python expert wrote it

This training course is for you because...

  • You work with many programming languages
  • You work with Python frequently
  • You want to become better at embracing Python’s unique features

Prerequisites

  • Required: Prior familiarity with Python, including comfort with loops, functions, dictionaries, lists, and classes.
  • Optional, but helpful: Knowledge of comprehensions, command-line arguments, and Python code style.

Recommended preparation:

  • Make sure that Python 3.7+ is installed on your machine.
  • The fully-refactored versions of Python files will be made available to attendees for download.

Recommended follow-up:

About your instructor

  • Trey Hunner helps software teams level up their Python skills through on-site Python training workshops and courses. Trey speaks at Python conferences, blogs about Python frequently, and runs Python Morsels, an online Python education service for individuals and small teams.

    Trey was formerly a director at the Python Software Foundation.

Schedule

The timeframes are only estimates and may vary according to how the class is progressing

Color Ratios function (10 minutes)

  • Introduction
  • Live Code Refactoring: 5 minutes
  • Q&A: 5 minutes

Get Earliest function (15 minutes)

  • Live Code Refactoring: 10 minutes
  • Q&A: 5 minutes

Fix CSV script (20 minutes)

  • Live Code Refactoring: 15 minutes
  • Q&A: 5 minutes

Interleave function (20 minutes)

  • Live Code Refactoring: 10 minutes
  • Q&A: 5 minutes
  • Break: 5 minutes

Sum Timestamps script (15 minutes)

  • Live Code Refactoring: 10 minutes
  • Q&A: 5 minutes

Vector class (15 minutes)

  • Live Code Refactoring: 10 minutes
  • Q&A: 5 minutes

Sort by Column script (15 minutes)

  • Live Code Refactoring: 15 minutes
  • Q&A: 5 minutes

All Same function (10 minutes)

  • Live Code Refactoring: 5 minutes
  • Q&A, wrap-up survey: 5 minutes