Is there any way in python to declare an enum's variables without values?
The syntax that works:
from enum import Enum
class Color(Enum):
Red = 'Red'
Blue = 'Blue'
Green = 'Green'
Since for this case the enum values are the same as the variable names, I'd like to avoid duplication.
Something like this maybe:
from enum import Enum
class Color(Enum):
Red
Blue
Green
This is why enum.auto() is a thing, so you don't need to write values explicitly.
from enum import Enum, auto
class Color(Enum):
Red = auto()
Blue = auto()
Green = auto()
You can also do print(Color.Red.name) to retrieve the name of the member :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With