with/as上下文管理器

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



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


#其上用法意义如下:
myfile=open(r'c:\missdata')
try:
    for line in myfile:
        print line
finally:
    myfile.close()
原文地址:https://www.cnblogs.com/dengyg200891/p/4923368.html