python之with open as

华景焕
2023-12-01

原文文章 http://www.cnblogs.com/ymjyqsx/p/6554817.html

with open('打开文件名','打开方式(w,r等)') as fp:
     fp.write(response.read())


等价于
try:
    f = open('打开文件名', '打开方式(w,r等)')
    print(fp.read())
finally:
    if fp:
        fp.close()

 类似资料: