Enums and switches

Monday 9 May 2005This is over 19 years old. Be careful.

The two most-often missed language features from Python are enums and switches. Recently, there seem to be a new crop of recipes at the Python Cookbook for implementing these. These two seem pretty good:

These are interesting for a few reasons: first, you can use them if you want to have enums or switches at your disposal in your Python code. Second, reading them and understanding how they are constructed usually provides a mini-tutorial in some dark corner of Python semantics. And third, the debate that springs up around them is usually rich in programming language philosophy and implementation topics.

Comments

[gravatar]
I thoroughly agree. The enumerations example, in particular, seems like a 'hello world' for the Python data model. A full-on goldmine in a thimble.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
Comment text is Markdown.