Using Python 3.4 I want to test whether an Enum class contains a member with a certain name.
Example:
class Constants(Enum):
One = 1
Two = 2
Three = 3
print(Constants['One'])
print(Constants['Four'])
gives:
Constants.One
File "C:\Python34\lib\enum.py", line 258, in __getitem__
return cls._member_map_[name]
KeyError: 'Four'
I could catch the KeyError
and take the exception as indication of existence but maybe there is a more elegant way?