Are you asking how you can have Color.red
and Color.blue
without blue
being an alias for red
?
If yes, you'll want to use the aenum
1 library and it would look something like:
from aenum import Enum, NoAlias
# python 3
class Color(Enum, settings=NoAlias):
green = 0
red = 1
blue = 1
# python 2
class Color(Enum):
_order_ = 'green red blue'
_settings_ = NoAlias
green = 0
red = 1
blue = 1
And in use:
for color in Color:
print(color.name)
print(color.value)
# green
# 0
# red
# 1
# blue
# 1
The downside of using NoAlias
is by-value lookups are disabled (you can't do Color(1)
).
1 Disclosure: I am the author of the Python stdlib Enum
, the enum34
backport, and the Advanced Enumeration (aenum
) library.