Why You Should Use Context Managers in Python

Artemis N.
Towards Data Science
5 min readNov 13, 2021

--

Photo by Anas Alshanti on Unsplash

What is a Context Manager

If you have used the with statement in Python then chances are you’ve already used a context manager.

A context manager usually takes care of setting up some resource, e.g. opening a connection, and automatically handles the clean up when we are done with it.

--

--