相关疑难解决方法(0)

打开读取并关闭1行代码中的文件

现在我使用:

pageHeadSectionFile = open('pagehead.section.htm','r')
output = pageHeadSectionFile.read()
pageHeadSectionFile.close()
Run Code Online (Sandbox Code Playgroud)

但为了使代码看起来更好,我可以这样做:

output = open('pagehead.section.htm','r').read()
Run Code Online (Sandbox Code Playgroud)

使用上述语法时,如何关闭文件以释放系统资源?

python readfile

109
推荐指数
7
解决办法
15万
查看次数

标签 统计

python ×1

readfile ×1