with/as上下文管理器

# -*- coding: utf-8 -*-
#python 27
#xiaodeng
#Python学习手册 868
#with/as上下文管理器



#with语句的基本格式:
with open(r'c:\miss\data') as myfile:
    for line in myfile:
        print line
#说明:
#对open的调用,会返回一个简单文件对象


#其上用法意义如下:
myfile=open(r'c:\\miss\data')
try:
    for line in myfile:
        print line
finally:
    myfile.close()

 

posted @ 2015-10-30 15:18  Xiao|Deng  阅读(176)  评论(0编辑  收藏  举报