如果我写这样的代码,会发生什么?文件对象会自动关闭吗?
# Do something before
# Make the value = 1 when the number in file.
for line in open('input_file.txt', 'r'):
index_list[int(line)] = 1
# Do something later
或者我必须编写这样的代码?
with open('xxx.txt', 'r') as f:
# Do something