I have created a Enum class as shown:
class MsgType(Enum):
# ADMINISTRATIVE MESSAGE
HEARTBEAT = "0"
LOGON = "A"
LOGOUT = "5"
REJECT_SESSION_LEVEL = "3"
RESEND_REQUEST = "2"
SEQUENCE_RESET = "4"
SESSION_REJECT = "3"
TEST_REQUEST = "1"
I want to use this class for comparison with a string that I get after reading a message. I am comparing the values as shown. The value in msg_type
is a of type str
.
def read_admin_msg(message):
msg_type = read_header(message)
if msg_type == ct.MsgType.HEARTBEAT:
print(msg_type)
elif msg_type == ct.MsgType.LOGON:
print(msg_type)
elif msg_type == ct.MsgType.LOGOUT:
print(msg_type)
elif msg_type == ct.MsgType.REJECT_SESSION_LEVEL:
print(msg_type)
elif msg_type == ct.MsgType.RESEND_REQUEST:
print(msg_type)
elif msg_type == ct.MsgType.SEQUENCE_RESET:
print(msg_type)
elif msg_type == ct.MsgType.SESSION_REJECT:
print(msg_type)
elif msg_type == ct.MsgType.TEST_REQUEST:
print(msg_type)
else:
print("Not found")
print(msg_type)
My expectation is that for msg_type = "A"
the statement msg_type == ct.MsgType.LOGON
should be True
but instead else
statement is executed.
If I write ct.MsgType.LOGON.value
then I get the desired result. But I want this behavior to be default for the class. Which method should I override or should I try a different approach?