小编mfc*_*era的帖子

Python打开和关闭文件 - 不直观

是我还是在python中打开或关闭文件使用不同的方法使它真的不直观?有没有更好的方法呢?

例:

f = open('file.txt', 'r')
try:
# do stuff with f
finally:
   f.close()
Run Code Online (Sandbox Code Playgroud)

现在,为什么我使用内置的"函数"打开但关闭文件我没有"关闭"功能,但我必须将"对象"方法称为"关闭".

python python-2.7

1
推荐指数
1
解决办法
180
查看次数

标签 统计

python ×1

python-2.7 ×1