From Martin Heinz
Some Cools Things contextlib
Can Do
- Trigger an object to close with
contextlib.closing
- Suppress warnings with
contextlib.suppress
. Equivalent to:
- Add
__enter__
and__exit__
functionality to functions via thecontextlib.ContextDecorator
mixin / decorator
There Are Three Types of Context Managers
- Single-use
- Reusable
- Reentrant—Reusable, and can be nested 🤯