为什么数据写入的是out_file变量,但结果会出现在to_filr中呢?(语言-python)

#读取数据后的数据写入了out_file变量,是哪一步完成了将数据写入to_file中呢?
#
from sys import argv
from os.path import exists

script, from_file, to_file = argv

print(f"Copping from {from_file} to {to_file}")

#we could do these two on one line, how?
in_file = open(from_file)
in_data = in_file.read()

print(f"The input file is {len(in_data)} bytes long")

print(f"Does the output file exists? {exists(to_file)}")
print("Ready, hit RETURN to continue, CTRL-C to abort.")
input()

out_file = open(to_file, 'w')
out_file.write(in_data)

print("Alright, all done")
in_file.close()
out_file.close()

img


to_file保存的是一个字符串,这个字符串是一个文件的路径
out_file = open(to_file, 'w')的意思是以w模式(覆盖写模式)去打开to_file(文件路径)文件。返回一个文件对象。
out_file.write(in_data),文件对象执行写入操作

但结果会出现在to_filr中呢?是to_file吧?
out_file是文件对象,通过write(in_data)将in_data中的数据写入to_file文件