PEP 354: Enumerations in Python
Steven Bethard
steven.bethard at gmail.com
Tue Feb 28 10:55:38 EST 2006
Ben Finney wrote:
> This PEP specifies an enumeration data type for Python.
>
> An enumeration is an exclusive set of symbolic names bound to
> arbitrary unique values. Values within an enumeration can be iterated
> and compared, but the values have no inherent relationship to values
> outside the enumeration.
-1 on the proposal as-is. I don't have many use cases for enumerations,
and I don't think they merit appearing in the builtins. If you put them
in the collections module instead, I'd probably be +0.
> This allows the operation to succeed, evaluating to a boolean value::
>
> >>> gym_night = Weekdays.wed
> >>> gym_night < Weekdays.mon
> False
> >>> gym_night < Weekdays.wed
> False
> >>> gym_night < Weekdays.fri
> True
> >>> gym_night < 23
> False
> >>> gym_night > 23
> True
> >>> gym_night > "wed"
> True
> >>> gym_night > Grades.B
> True
For the few cases of enumerations that I've needed, I've never wanted
them to be comparable with <, >, etc. If there were two classes, say
``collections.Enum`` and ``collections.OrderedEnum`` where only the
latter made the enumerated items comparable, you might even get me as
high as +0.5. (I only care about the non-comparable one, but I
understand that others may have a need for the comparable one.)
STeVe
More information about the Python-list
mailing list