June 2017
Beginner to intermediate
274 pages
6h 49m
English
In this section, we'll look at what is maybe Python's most-used programmable semantic element—context managers.
Context managers are pieces of code that plug into Python's with statement. A with statement contains a block of code, and the context manager is able to run its own code, both before and after that block is executed, along with the after code guaranteed to run no matter what happens in the block.
The Python standard library makes quite a lot of use of context managers:

Read now
Unlock full access