I have en Enum type:
class SystemCommands(Enum):
Get_FW_version = (0, 1)
Get_MAC_address = (1,1)
Set_MAC_address = (2,7)
Get_IP_addr = (3,1)
Set_IP_addr = (4,5)
Get_server_IP_addr = (5,1)
Set_server_IP_addr = (6,5)
Get_subnet_Mask = (7,1)
Set_subnet_Mask = (8,5)
Get_Gateway_Address = (9,1)
Set_Gateway_Address = (10,5)
Welcome = (16,1)
Request_Cannot_Served = (17,1)
def __init__(self, CommandCode, length):
self.CommandCode = CommandCode
self.length = length
I would like to create an enum variable based only on an int value:
code =10
...
Request = SystemCommands(code)
Of course i got a nice excpetion:
raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: 10 is not a valid SystemCommands
Question: How can I create a complex-typed enum based only one value?