What is the python “with” statement designed for?

后端 未结 10 2036
心在旅途
心在旅途 2020-11-21 07:52

I came across the Python with statement for the first time today. I\'ve been using Python lightly for several months and didn\'t even know of its existence! G

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 07:54

    points 1, 2, and 3 being reasonably well covered:

    4: it is relatively new, only available in python2.6+ (or python2.5 using from __future__ import with_statement)

提交回复
热议问题