Easier Classes:
Python Classes Without All The Cruft
Hello!
This is the resources page for my talk, Easier Classes: Python Classes Without All the Cruft. This page contains information about the slides, links to tools and resources I mentioned in my talk, other recordings of this talk, information about me. If you'd like to start a conversation with me or keep up with my work, you can find details on me at the bottom of this page.
The slides
You can find the slides for the talk here.
The most important links
I talked about both third-party packages and standard library modules during my talk. Here are links to the most important things I discussed in order:
total_ordering
typing.NamedTuple
(and the oldercollections.namedtuple
)attrs
- Stop Writing Classes
Recording of this talk
You can watch the recording of this talk below.
The "B Sides" slides
There are a few interesting dataclasses features that I didn't mention during my talk. Some of these I didn't mention for the sake of time and some of these dive just a bit more into dataclasses than I had planned in this talk.
These missing slides include the following extra information:
- If you wish dataclasses supported a specific bit of extra field-specific functionality, you might be able to implement it yourself by adding metadata to each of your dataclass fields.
- If you'd like to make some fields ignored in equality and ordering comparisons, you can make non-comparable dataclass fields.
- You can also use a factory function for default values with the
default_factory
field argument. - And you can make generated attributes that are made after initialization with the init=False field argument and a
__post_init__
method.
You can find me presenting some of these slides in this live online presentation I gave for the PyHouston meetup.
Related resources
- How to make an iterator in Python
- TUple ordering and deep comparisons in Python
__setattr__
documentation__hash__
documentation- "Dataclasses are here! Now what?" - Scott Irwin
- A brief tour of Python 3.7 dataclasses
Who Am I?
My name is Trey and I help professional programmers improve their Python skills.
I run a Python skill-building service for individuals called
I write articles regularly at treyhunner.com. If you'd like to keep up with my writing, sign up for my email newsletter. You can also find me on Twitter as @treyhunner.
Chat with me about team learning
If you work in a team of folks who get paid to write Python code, I would love to chat about your team's Python skill-building strategies with you.
If you'd like to brainstorm team learning strategies with me, click the button below, fill out the form, and we'll chat.
Build your Python skills every week
The best way to improve your skills is to practice. It's hard to practice unless you have a regimen and a routine. Making a practice routine on your own is time-consuming and hard.
Python Morsels can help! Through Python Morsels, every Monday I send out one Python exercise. These exercise are meant to help professional Python programmers to hone their skills, not brand new programmers. They've been described as "Kreutzer's etudes for Python" and "like a reverse code review".
I send out the exercise on Monday morning which includes a base problem, bonuses, and automated tests to run against your code. The exercise should take you up to 30 minutes. On Wednesday I send out an email explaining different solutions for the exercise and why we might choose one technique over another.
If you'd like to try these out yourself, type in your email below: