[Python-ideas] PEP for enum library type?

Guido van Rossum guido at python.org
Wed Feb 13 00:12:02 CET 2013


Well but you will use them as loglevels.debug, right?

On Tue, Feb 12, 2013 at 3:09 PM, Markus Unterwaditzer
<markus at unterwaditzer.net> wrote:
> 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



--
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list