[Python-ideas] PEP for enum library type?

Tim Delaney timothy.c.delaney at gmail.com
Wed Feb 13 20:22:11 CET 2013


On 14 February 2013 05:14, Barry Warsaw <barry at python.org> wrote:

> On Feb 12, 2013, at 02:13 PM, Eli Bendersky wrote:
>
> >I agree, and Tim's implementation provides a very nice string
> >representation, no matter what the value underneath is. I don't really
> care
> >what the value underneath is, actually.
>
> Except that sometimes you do, which is why flufl.enum has a nice concise
> str
> and a more detailed repr.  The former doesn't include the underlying value
> while the latter does.  Edible cake.
>

Yes - my enum's exactly the same - simple, concise str (for both the enum
and values) and detailed repr. The actual repr is a little different to
flufl.enum repr (I think the str is the same) but conveys the same
information.

Color.RED
<EnumValue 'Color.RED': 0>

{RED:0, GREEN:1, BLUE:2, CYAN:10, MAGENTA:11, YELLOW:12, BLACK:127}
<enum __main__.Color {<EnumValue 'RED': 0>, <EnumValue 'GREEN': 1>,
<EnumValue 'BLUE': 2>, <EnumValue 'CYAN': 10>, <EnumValue 'MAGENTA': 11>,
<EnumValue 'YELLOW': 12>, <EnumValue 'BLACK': 127>}>

Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130214/bb40105c/attachment.html>


More information about the Python-ideas mailing list