I have a class which inherits from Enum
and str
. I need to define some class attributes which are defined in a .json file and is being loaded in a Python dictionary.
from enum import Enum
# I want to create a class like this (but assign the class attributes by reading a dict)
class Test(str, Enum):
A = 'Alpha'
B = 'Beta'
# Attempt to solve :
mydict = { 'A' : 'Alpha', 'B' : 'Beta' }
class Test1(str, Enum):
for k,v in mydict.items():
k = v
# => An Error is reported here.
For class instances, I can use setattr()
but I could not find anything to set the class attributes.
Since these attributes are dynamic and could change, I do not want to hard-code the class attributes but rather read in a dictionary and set it.