On Thu, Apr 25, 2013 at 2:42 AM, Antoine Pitrou <solip...@pitrou.net> wrote:

> Le Fri, 12 Apr 2013 05:55:00 -0700,
> Eli Bendersky <eli...@gmail.com> a écrit :
> >
> > To programmatically access enumeration values, use ``getattr``::
> >
> >     >>> getattr(Colors, 'red')
> >     <EnumValue: Colors.red [value=1]>
>
> The PEP should mention how to get an enum from its raw value:
>
>     >>> Colors[1]
>     <EnumValue: Colors.red [value=1]>
>
>
Yes, this is mentioned in the beginning of the same paragraph.


> or:
>
>     >>> Colors(1)
>     <EnumValue: Colors.red [value=1]>
>
>
This syntax was considered initially but then rejected because it's
confusing, and there already exists a way to lookup by value (Colors[1]).

Eli



> It would perhaps be nice to have a .get() method that return None if the
> raw value is unknown:
>
>     >>> Colors(42)
>     ...
>     ValueError: 42
>     >>> Colors.get(42)
>     >>>
>
> Regards
>
> Anroine.
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev@python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/eliben%40gmail.com
>
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to