2 ms·
Even better (with Python 3.5 or newer): from contextlib import suppress with suppress(OSError): os.remove(temp_file) More generally, context
by shoyer 11y ago
Even better (with Python 3.5 or newer):
from contextlib import suppress
with suppress(OSError):
os.remove(temp_file)
More generally, context managers are the right way to refactor repeated try/except/finally clauses.
- amyjess 11y agoWell, I have yet another reason to migrate from 2 to 3 now.