I want to create a list (not implying Python List) of error messages and corresponding error codes. I have two requirements – be able to look up the error message given an error code and be able to perform the opposite look-up.
- Is there a native python data type that can achieve this? If not, how should I implement this?
- This list of error messages + codes would be used by BusinessRuleViolation, a custom exception class. I want this list to associate with BusinessRuleViolation and shouldn’t be modified during runtime. How can I do that?
Typically you’d do this with a pair of
dicts – one mapping error codes to messages, and then another one (often programmatically generated) with the reverse mapping.Then you can do lookups with
[]: