代码改变世界

随笔档案-2016年02月

Python 的with语句

2016-02-18 14:53 by 风依然, 207 阅读, 收藏,
摘要: 1、使用 with 语句操作文件对象 with open(r'somefileName') as somefile: for line in somefile: print line # ...more code 这里使用了 with 语句,不管在处理文件过程中是否发生异常,都能保证 with 语句 阅读全文