- Mastering Concurrency in Python
- Quan Nguyen
- 130字
- 2021-06-10 19:24:05
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]
推薦閱讀
- C++程序設計教程
- Extending Jenkins
- FreeSWITCH 1.8
- Developing Middleware in Java EE 8
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第2版)
- 精通MATLAB(第3版)
- Haskell Data Analysis Cookbook
- 常用工具軟件立體化教程(微課版)
- Java網絡編程實戰
- Python項目實戰從入門到精通
- 區塊鏈架構之美:從比特幣、以太坊、超級賬本看區塊鏈架構設計
- C++ System Programming Cookbook
- 高質量程序設計指南:C++/C語言
- 計算機應用基礎(Windows 7+Office 2010)
- Elasticsearch實戰(第2版)