【发布时间】:2013-01-01 02:13:05
【问题描述】:
可能重复:
Does filehandle get closed automatically in Python after it goes out of scope?
我是 python 新手。我知道如果你打开一个文件并写入它,你需要在最后关闭它。
in_file = open(from_file)
indata = in_file.read()
out_file = open(to_file, 'w')
out_file.write(indata)
out_file.close()
in_file.close()
如果我这样写代码。
open(to_file, 'w').write(open(from_file).read())
我真的不能关闭它,它会自动关闭吗?
【问题讨论】:
标签: python python-2.7