既然 open(from_file) 得到的 file object 没有保存到任何变量,已经没法再使用了,是不是执行完这一行就释放了呢?如果不是的话,这样写可不可以手动关闭呢:
from_file = 'sample.txt'
indata = open(from_file).read()
open(from_file).close()
from_file = 'sample.txt'
indata = open(from_file).read()
open(from_file).close()