You can try using getattr
:
from enum import Enum
class Animals(Enum):
Dog = 1
Cat = 2
Cow = 3
Choose = input('Choose an animal')
print(getattr(Animals, Choose).value)
Output:
1
getattr
stands for "get attribute", which means it gets the variable in the class which it's name is what the second argument is.
Enum
s have already builtin __getitem__
methods, so you can directly index it with []
brackets, like this:
print(Animals[Choose].value)
Output:
1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…