摘要: with语句一般用于文件打开,避免使用如下繁琐的格式:fd = Nonetry: fd = open("./hello.txt") for line in fd: print lineexcept Exception as e: print efinally: fd.close()使用with语句如下:with open("./hello.txt") as f: for line in f: print line其他更cool的用法,留到以后慢慢收集。 阅读全文
posted @ 2014-01-14 16:36 jaw-crusher 阅读(136) 评论(0) 推荐(0)