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 _______________________________________________ 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