Le Fri, 12 Apr 2013 05:55:00 -0700,
Eli Bendersky <[email protected]> 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]>
or:
>>> Colors(1)
<EnumValue: Colors.red [value=1]>
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
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com