Currently, I have an enum that represents a name/number mapping. Each EventType, however, also has additional "related properties" (e.g. a status code, and a message type).
class EventType(Enum):
CANCELLED = 0
ONTIME = 1
DELAYED = 2
def get_status(self):
if self == EventType.CANCELLED:
return "statuscode1"
elif self == EventType.DELAYED:
return "statuscode2"
else:
return "statuscode3"
def get_message_type(self):
if self == EventType.CANCELLED:
return "messagetype1"
elif self == EventType.DELAYED:
return "messagetype2"
else:
return "messagetype3"
Instead of creating the methods above and tons of if chains checking against self, is there a cleaner way of refactoring to return the status codes and message types? It's almost as if CANCELLED = (0, statuscode1, messagetype1).. How can I represent this concept in an enum? Is an enum even the correct way to do this?
Enumtype.