Build your own kind of dictionary

This is the video from my PyOhio talk on building objects that can act like dictionaries.

The text and programs from my talk on building your own are available here on github. You can probably absorb the information most quickly by reading the talk.rst file.

Please let me know if you find spelling errors or goofy sentences that are hard to understand that I should rewrite.

This is the description for the talk:

My talk is based on a project that seemed very simple at first. I wanted an object like the regular python dictionary, but with a few small tweaks:

  • values for some keys should be restricted to elements of a set
  • values for some keys should be restricted to instances of a type

For example, pretend I want a dictionary called favorites, and I want the value for the “color” key to be any instance of my Color class. Meanwhile, for the “movie” key, I want to make sure that the value belongs to my set of movies.

In the talk, I’ll walk through how I used tests to validate my different implementations until I came up with a winner.

Unlike my talk last year on metaclass tomfoolery, and the year before that on fun with decorators (and decorator factories) I’m hoping to make this talk straightforward and friendly to beginning programmers.

You’ll see:

  • how I use tests to solve a real-world problem
  • a few little gotchas with the super keyword
  • a little about how python works under the hood