Skip to content

Glossary: Python Beyond the Basics

context manager

Also written: contextmanager, contextlib, context managers

An object that works with `with`, setting something up at the start and cleaning up at the end, like `open` closing a file. You can write one with the `@contextmanager` decorator around a generator that has one `yield`.

Where the book teaches it

Related terms

generatordecorator