Python·100 questions

What are context managers (contextlib.contextmanager)?

Answer
Allows writing with statements via generator.
@contextmanager decorator on a function.
yield separates enter/exit.
Do cleanup in finally.
Useful for temporary settings/resources.
Was this answer helpful?

More questions in this topic

Related questions from other topics