Le Fri, 12 Apr 2013 05:55:00 -0700,
Eli Bendersky <eliben at 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]>
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.