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

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]
主站蜘蛛池模板: 丹东市| 湖南省| 集安市| 平阳县| 绥德县| 东辽县| 芦山县| 榆中县| 康保县| 福鼎市| 红原县| 德江县| 大邑县| 仪陇县| 兴城市| 嘉荫县| 龙南县| 巩义市| 灌阳县| 平江县| 皋兰县| 湘潭市| 阜城县| 右玉县| 平舆县| 广昌县| 澜沧| 大荔县| 凯里市| 含山县| 高邑县| 千阳县| 中方县| 龙口市| 张家口市| 南阳市| 吉木乃县| 宾川县| 东阿县| 安义县| 靖州|