The syntax of the with statement

The syntax of the with statement can be intuitive and straightforward. With the purpose of wrapping the execution of a block with methods defined by a context manager, it consists of the following simple form:

with [expression] (as [target]):
[code]

Note that the as [target] part of the with statement is actually not required, as we will see later on. Additionally, the with statement can also handle more than one item on the same line. Specifically, the context managers created are treated as if multiple with statements were nested inside one another. For example, look at the following code:

with [expression1] as [target1], [expression2] as [target2]:
[code]

This is interpreted as follows:

with [expression1] as [target1]:
with [expression2] as [target2]:
[code]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.179.59