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

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]
主站蜘蛛池模板: 临沂市| 恩平市| 泸溪县| 南雄市| 通辽市| 光山县| 河东区| 新沂市| 浪卡子县| 金溪县| 通道| 呼伦贝尔市| 杨浦区| 长顺县| 涿鹿县| 北宁市| 宁城县| 炉霍县| 通榆县| 嘉义市| 吉木萨尔县| 涞水县| 镇康县| 本溪市| 汉源县| 青阳县| 尚志市| 南丹县| 万安县| 伊通| 河曲县| 南丹县| 东安县| 沂水县| 虹口区| 玉溪市| 德昌县| 东阿县| 闵行区| 盖州市| 赤水市|