首页 > 其他 > 详细

Context Managers and else Blocks

时间:2020-03-09 09:25:02      阅读:61      评论:0      收藏:0      [点我收藏+]

In this chapter, we will discuss control flow features that are not so common in other languages, and for this reason tend to be overlooked or underused in Python. They are:

  • The with statement and context managers
  • The else clause in for, while, and try statements

The with statement sets up a temporary context and reliably tears it down, under the control of a context manager object. This prevents errors and reduces boilterplate code, making APIs at the same time safer and easier to use. Python programmers are finding lots of uses for with blocks beyond automatic file closing.

 

 

 

 

 

 

 

 

 

 

end...

Context Managers and else Blocks

原文:https://www.cnblogs.com/neozheng/p/12446165.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!