Skip to main content

← All terms · Errors & control flow

Context manager

An object usable with `with`. Guarantees cleanup even on exception — `open()`, locks, DB sessions.

Learn this interactively:

Open lesson lesson-108

Related — Errors & control flow

ExceptionAn object that signals something went wrong. Raised with `raise`, caught with `ttry / except / finallyHandle exceptions. `finally` always runs (cleanup). Catching `Exception` is usuaEAFP“Easier to Ask Forgiveness than Permission”. Idiomatic Python: try the operation