PEP 354: Enumerations in Python

Tim Chase python.list at tim.thechases.com
Mon Feb 27 04:13:08 EST 2006


> Uniqueness imposes an odd constraint that you can't have 
> synonyms in the set:
> 
>  >>> shades = enum({white:100, grey:50, gray:50, black:0})

Blast, I hate responding to my own posts, but as soon as I 
hit Send, I noticed the syntax here was biffed.  Should have 
been something like

 >>> shades = enum(("white", 100), ("grey", 50), 
("gray",50), ("black", 50))

Same could go for days of the week:

 >>> dow=enum(("sunday", 0), ("monday", 1), 
("start_of_work_week", 1), ... ("friday", 5), 
("end_of_work_week", 5)...)

Given more little grey cells (or gray cells?), I'm sure  I 
could come up with more examples of when it's handy to have 
duplicate values in an enum...

-tkc






More information about the Python-list mailing list