官术网_书友最值得收藏!

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]
主站蜘蛛池模板: 清苑县| 资兴市| 寻乌县| 晋江市| 酒泉市| 通榆县| 开远市| 闻喜县| 措美县| 马山县| 修水县| 白沙| 化德县| 大埔区| 安塞县| 太谷县| 乌恰县| 伊金霍洛旗| 富锦市| 建水县| 资中县| 米泉市| 兴国县| 同德县| 三门峡市| 台安县| 拜泉县| 察隅县| 盐源县| 大安市| 和田县| 武平县| 玉门市| 土默特右旗| 筠连县| 定襄县| 峡江县| 化州市| 大港区| 黎城县| 海林市|