Consider the following code.
How does python interpret class RottenFruit
when it is comma separated? Is this legal? If yes, what is the use case?
from enum import Enum
class Fruit(Enum):
Apple = 4
Orange = 5
Pear = 6
a = Fruit(5)
class RottenFruit(Enum):
Apple = 4,
Orange = 5,
Pear = 6
print(Fruit(5))
print(RottenFruit(5))
output:
Fruit.Orange
Traceback (most recent call last):
File "...\tests\sandbox.py", line 15, in <module>
print(RottenFruit(5))
File "...\AppData\Local\Programs\Python\Python36\lib\enum.py", line 291, in __call__
return cls.__new__(cls, value)
File "...\AppData\Local\Programs\Python\Python36\lib\enum.py", line 533, in __new__
return cls._missing_(value)
File "...\AppData\Local\Programs\Python\Python36\lib\enum.py", line 546, in _missing_
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 5 is not a valid RottenFruit