什么是python关键字"with"用于?
示例来自:http://docs.python.org/tutorial/inputoutput.html
>>> with open('/tmp/workfile', 'r') as f:
... read_data = f.read()
>>> f.closed
True
Run Code Online (Sandbox Code Playgroud) 我with今天第一次遇到了Python 语句.我已经使用Python几个月了,甚至不知道它的存在!鉴于其地位有点模糊,我认为值得问:
with设计用于的Python 语句? try..finally比它更好用的情况with?