PEP 354: Enumerations in Python

Christos Georgiou tzot at sil-tec.gr
Fri Mar 3 04:19:08 EST 2006


On 26 Feb 2006 22:30:28 -0800, rumours say that "Crutcher"
<crutcher at gmail.com> might have written:

>This seems great, except why can't I compare strings? It seems too
>useful when dealing with user input, or parsing messages or config
>files.
>
>>>> Weekdays = enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
>>>> Weekdays.mon.__cmp__('mon')

some_value = Weekdays.thu
...
user_input = raw_input("Enter day name")
if user_input == str(some_value):

>Additionaly, perhaps the call method of the enumeration object should
>construct a value from strings?
>>>> Weekdays.mon == Weekdays('mon')

Either way works for me.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians



More information about the Python-list mailing list