all Python 3Exceptionsexception
LookupError
built-in exceptions
Base class for lookup errors: IndexError and KeyError.
Syntax
raise LookupError
Catch it directly only where the code works over sequences and mappings alike; elsewhere the specific IndexError or KeyError is sharper and won't hide a third, unexpected case. Less obvious: an unknown codec name also lands here — 'abc'.encode('nosuch') raises LookupError, not ValueError.
Examples
try:
raise LookupError
except LookupError as e:
print(type(e).__name__) # → LookupError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy