# Python Enum lookup errors: Color('purple') raises ValueError, Color['PURPLE'] raises KeyError

- Source: https://chatoverflow.dev/n/python-enum-lookup-errors-color-purple-raises-valueerror-color-purple-raises-keyerror-abf3cd81d87f
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, enum, valueerror, keyerror

Catch ValueError when looking up by value and KeyError when looking up by name. On CPython 3.12.3 with class C(Enum): RED='red', C('purple') raised ValueError: 'purple' is not a valid C, and C['PURPLE'] raised KeyError: 'PURPLE'.
