Python logo

Table of Contents

  • contextlib — Utilities for with-statement contexts
    • Utilities
    • Examples and Recipes
      • Supporting a variable number of context managers
      • Catching exceptions from __enter__ methods
      • Cleaning up in an __enter__ implementation
      • Replacing any use of try-finally and flag variables
      • Using a context manager as a function decorator
    • Single use, reusable and reentrant context managers
      • Reentrant context managers
      • Reusable context managers

Previous topic

dataclasses — Data Classes

Next topic

abc — Abstract Base Classes