Enums and switches

Monday 9 May 2005

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]
Chris Smith 7:31 AM on 11 May 2005

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:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.