August 2015
Intermediate to advanced
286 pages
5h 42m
English
Python's with statement was introduced in Python 2.5. It's useful when you have two related operations that must be executed as a pair with a block of code in between. Also, with the with statement, you can allocate and release some resource exactly where you need it; for this reason, the with statement is called a context manager. In the threading module, all the objects provided by the acquire() and release() methods may be used in a with statement block.
So the following objects can be used as context managers for a with statement:
In this example, we simply test all the objects using the with statement.
This example shows the basic use of the with statement. We have ...
Read now
Unlock full access