Programmatic access to enumeration members and their attributes
https://docs.python.org/3/howto/enum.html#programmatic-access-to-enumeration-members-and-their-attributes
Sometimes it’s useful to access members in enumerations programmatically (i.e. situations where Color.RED won’t do because the exact color is not known at program-writing time). Enum allows such access:
class Color(Enum):
RED = 1
GREEN = 2
BLUE = 3
Color(1)
<Color.RED: 1>
Color(3)
<Color.BLUE: 3>
If you want to access enum members by name, use item access:
Color['RED']
<Color.RED: 1>
Color['GREEN']
<Color.GREEN: 2>
If you have an enum member and need its name or value:
member = Color.RED
member.name
'RED'
member.value
1