标签:enc man 上下 print context yield close pat open
import queue
import contextlib
q=queue.Queue()
li=[]
@contextlib.contextmanager
def my_open(file_path,val):
f=open(file_path,mode=val,encoding=‘utf-8‘)
try:
yield f
finally:
f.close()
with my_open(‘ag.txt‘,‘w‘) as f1:
print(f1.readline)
标签:enc man 上下 print context yield close pat open
原文地址:http://www.cnblogs.com/chengguxian/p/7784396.html