[Python-ideas] PEP for enum library type?

Markus Unterwaditzer markus at unterwaditzer.net
Wed Feb 13 00:09:49 CET 2013


Guido van Rossum <guido at python.org> wrote:

>On Tue, Feb 12, 2013 at 2:50 PM, Markus Unterwaditzer
><markus at unterwaditzer.net> wrote:
>> Forgive my naiveness, but why do we need a new type for enums?
>Wouldn't a new builtin function that returns a dict suffice? Something
>like:
>>
>> def enum(*keys):
>>     return dict((k, i) for i, k in enumerate(keys))
>>
>> loglevels = enum('debug', 'warning', 'error')
>
>Because you shouldn't have to put the enum names in quotes.

Oh, I thought you were just against quoted names if they were also accessible without those:

>Whenever I see quoted names that are also used unquoted, I cringe a little (and this includes calls to hasattr() or getattr() with a string literal for the name).
-- Markus



More information about the Python-ideas mailing list