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?

Join expert Trey Hunner to learn how to refactor your Python code. Using “mob programming,” where attendees all work together as a group, this course will get you up to speed on converting programs with unidiomatic Python code to programs that embrace the full power of Python. Along the way, you’ll explore the Python features that can help you improve the readability and clarity of your code.

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

By the end of this live 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

  • A computer with Python 3.7+ installed
  • A working knowledge of Python, including loops, functions, dictionaries, lists, and classes
  • Familiarity with comprehensions, command-line arguments, and Python code style (useful but not required)

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)

  • Presentation and live-code refactoring
  • Q&A

Get earliest function (15 minutes)

  • Presentation and live-code refactoring
  • Q&A

Fix CSV script (20 minutes)

  • Presentation and live-code refactoring
  • Q&A

Interleave function (15 minutes)

  • Presentation and live-code refactoring
  • Q&A

Break (5 minutes)

Sum timestamps script (15 minutes)

  • Presentation and live-code refactoring
  • Q&A

Vector class (15 minutes)

  • Presentation and live-code refactoring
  • Q&A

Sort by column script (15 minutes)

  • Presentation and live-code refactoring
  • Q&A

All same function (5 minutes)

  • Presentation and live-code refactoring

Wrap-up and Q&A (5 minutes)