Open this example in the interactive library
Source code
from contextlib import suppress
with suppress(KeyError):
{}['missing']
print('Continued')Sample output
Continued

Suppress a specific exception. A self-contained example using the Python standard library.
Open this example in the interactive library
from contextlib import suppress
with suppress(KeyError):
{}['missing']
print('Continued')Continued