[Python-ideas] str-type enumerations
Eli Bendersky
eliben at gmail.com
Thu Apr 4 15:56:54 CEST 2013
On Wed, Apr 3, 2013 at 8:23 PM, Eli Bendersky <eliben at gmail.com> wrote:
> On Tue, Apr 2, 2013 at 12:25 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
>
>> I'm not trying to beat this dead horse (really!) but back when the
>> enumeration discussions were going fast and furious one of the things asked
>> for was enumerations of type str, to which others replied that strings
>> named themselves.
>>
>> Well, I now have a good case where I don't want to use the string that
>> names itself: 'Mn$(1,6)' I would match rather write item_code! :)
>>
>
> Hi Ethan,
>
> The latest incarnation of flufl.enum that went through the round of
> discussions during PyCon allows string values in enumerations, if you want
> them:
>
> >>> from flufl.enum import Enum
> >>> class WeirdNames(Enum):
> ... item_code = 'Mn$(1,6)'
> ... other_code = '#$%#$^'
> ...
> >>> WeirdNames.item_code
> <EnumValue: WeirdNames.item_code [value=Mn$(1,6)]>
> >>> i = WeirdNames.item_code
> >>> i
> <EnumValue: WeirdNames.item_code [value=Mn$(1,6)]>
> >>> i.value
> 'Mn$(1,6)'
> >>> print(i)
> WeirdNames.item_code
> >>>
>
> I haven't updated PEP 435 to reflect this yet, hope to do so in the next
> day or two.
>
The PEP is up-to-date now, and mentions string-valued enums as well.
Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130404/02cb459f/attachment.html>
More information about the Python-ideas
mailing list