首页 > 编程语言 > 详细

python with as

时间:2016-03-24 12:52:51      阅读:223      评论:0      收藏:0      [点我收藏+]

参考:http://zhoutall.com/archives/325

开了文件就得关,

 

用 with as 就省了 finally

try:
    with open( "a.txt" ) as f :
        do something
except xxxError:
    do something about exception

with-as表达式极大的简化了每次写finally的工作,这对保持代码的优雅性是有极大帮助的。

python with as

原文:http://www.cnblogs.com/pudding-ai/p/5314788.html

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