Easier Classes: Python Classes Without All the Cruft
By Trey Hunner

In this talk we'll take a look at how to cut down on the boilerplate required in making a well-behaved Python class. We'll first see how to make classes with proper string representations, comparability, iterability, and immutability. Then we'll dive into helper tools built-in to the standard library and available in third-party libraries.

Saturday 10:30 a.m.–11 a.m. in Cartoon 1

When bundling up data, sometimes tuples and dictionaries don't quite cut it. Python's classes are powerful tools for data storage and manipulation, but it can take quite a bit of boilerplate code to make a well-behaved Python class. In this talk we're going to discuss how a well-behaved class should work and take a look at a number of helper libraries for creating well-behaved classes.

We'll first see how to make classes with proper string representations, comparability, iterability, and immutability. Then we'll dive into helper tools built-in to the standard library and available in third-party libraries.

We'll look at namedtuple, NamedTuple (not a typo), attrs, and the new Python 3.7 dataclasses.

Most of the libraries discussed in this talk are only available in Python 3, so if you're not using Python 3, hopefully this talk will encourage you to upgrade.

Trey Hunner

Trey Hunner helps Python and Django teams turn experienced developers into experienced Python developers through on-site team training. Trey's training sessions are always hands-on and skill-oriented.

Trey tweets about Python, holds live Python webcasts, and sends weekly Python exercises to new learners.

Trey is a director at the Python Software Foundation, a member of the Django Software Foundation, a Django Girls San Diego co-organizer, and a co-organizer of San Diego Python.

Twitter
Sponsors