Dec 5, 2022
Good article.
I would just add that context managers aren't just used to manage resources. For example in the Python graphics library generativepy, Transform operations are context managers.
For example if you want to scale the drawing space you can use Transform to scale the space, then everything you draw will be larger. But you must remember to remove the scaling when you are finished.
Since Transform is a context manager, you can use a with statement to automatically remove the scaling at the end of the block.