In Python3.7.7, I would like to use the name of an Enum value in the declaration of another value of the same Enum.
My first try:
from enum import Enum
class test(Enum):
value1 = "a"
value2 = value1.name + "b"
This returns an AttributeError: 'str' object has no attribute 'name'
. I tried using self.value1
and test.value1
instead and both return a NameError
.
I could just use value2 = "value1b"
but I fear that it would give me weird errors down the line if I ever change the name of value1
and forget some places instead of an immediate error because of an undefined variable.