PEP 354: Enumerations in Python
Tim Chase
python.list at tim.thechases.com
Mon Feb 27 03:32:26 EST 2006
Just a couple thoughts:
> An enumeration is an exclusive set of symbolic names bound
> to arbitrary unique values.
Uniqueness imposes an odd constraint that you can't have
synonyms in the set:
>>> shades = enum({white:100, grey:50, gray:50, black:0})
Not a bad thing, as it would then have interesting results
upon iterating (would the above example have three or four
passes through the iteration loop?), but there could be some
handy uses for enums containing duplicates.
> >>> Grades = enum('A', 'B', 'C', 'D', 'F')
This produces the counter-intuitive result of
>>> Grades.A > Grades.B
False
Sure, one can bung with it and create the set of grades
backwards, but then iteration becomes weird. Perhaps the
ability to override the comparitor?
-tkc
More information about the Python-list
mailing list