Re: PEP 354: Enumerations in Python
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: PEP 354: Enumerations in Python

From: Steven Bethard <steven.bethard@gmail.com>
Date: Tue Feb 28 2006 - 16:55:38 CET

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
Received on Sun Apr 30 10:29:15 2006