I have defined two enums with attributes. When I want to access an enum element by specifying its attribute it works for enum A (one attribute) but not for enum B (two attributes):
from enum import Enum
class A(Enum):
ValOne = ('One')
ValTwo = ('Two')
def __init__(self, num):
self.num = num
class B(Enum):
ValOne = ('Val', 'One')
ValTwo = ('Val', 'Two')
def __init__(self, val, num):
self.val = val
self.num = num
print(A('One'))
print(B('Val', 'One'))
I get the following output:
A.ValOne
Traceback (most recent call last):
File "test.py", line 19, in <module>
print(B('Val', 'One'))
File "/usr/lib/python3.8/enum.py", line 341, in __call__
return cls._create_(
File "/usr/lib/python3.8/enum.py", line 444, in _create_
_, first_enum = cls._get_mixins_(cls, bases)
File "/usr/lib/python3.8/enum.py", line 576, in _get_mixins_
raise TypeError("Cannot extend enumerations")
TypeError: Cannot extend enumerations
What am I missing here?