Avatar

ups and downs

Tobiasz Kedzierski's blog.

Python, Django, the cloud, and other interesting things — computer-related or not.

Mostly monthly round-ups of what I've been doing, reading and watching.

  1. tobked.dev
  2. Email
  3. GitHub
  4. LinkedIn
  5. Credly
  6. Medium
  7. RSS
  1. Home
  2. About me
  3. Links
  4. Archives
  5. Search
    1. Dark Mode

Table of contents

  • Handling exceptions with contextlib.supress()
Python

Handling exceptions with contextlib

Wednesday, February 27, 2019 1 minute read
Table of contents
  • Handling exceptions with contextlib.supress()

Handling exceptions with contextlib.supress()

import contextlib

with contextlib.suppress(FileNotFoundError):
    os.remove("somefile.tmp")

This is equivalent to the following try/except clause:

try:
    os.remove("somefile.tmp")
except FileNotFoundError:
    pass


Sources:

  • Python Tricks Email series from RealPython.com
Python Exception Exceptions Context

Related content

Page Object Pattern in testing Django

Model property in Django

Custom context processors in Django

links

© 2018 - 2026 ups and downs
Profile photo by Julia Kaczorowska (other photos by me).
Built with Hugo
Theme Stack designed by Jimmy