38. Deleting a file

The key here is to avoid the try/except code and favor a context manager approach.

38.1. Don’t do this

1import os
2
3try:
4    os.remove('test.tmp')
5except OSError:
6    pass

38.2. Do this

1from contextlib import suppress
2
3with suppress(OSError):
4    os.remove('test.tmp')