On Apr 25, 2013, at 11:42 AM, Antoine Pitrou wrote: >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]> No, this is a failed experiment. It's deprecated in flufl.enum and shouldn't make it into stdlib enum. getitem syntax is TOOWTDI. >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) > >>> class Methods(Enum): set = 1 get = 2 delete = 3 What is "Methods.get"? Catching the ValueError ``Methods[5]`` would raise doesn't seem so bad. -Barry
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4