from sys import argv
from os.path import exists
script, to_file, in_file = argv
print(f"copying {to_file} to {in_file}")
x_file = open(to_file)
indata = x_file.read()
print(x_file.read())
print(f"Does the output file exists? {exists(in_file)}")
print("Ready, hit RETURN to choutinue, or CTRL-C abort")
input()
y_file = open(in_file, 'w')
y_file.write(indata)
x_file.close()
y_file.close()
练习时,
x_file = open(to_file)
indata = x_file.read()
print(x_file.read())
这部分的2,3行位置是颠倒的,print语句是我在教程额外添加的,执行后 in_file一直为空。
之后颠倒位置后,发现可以正常复制to_file 到in_file 中
通过百度找到了该知识点,因为read() 是指针类型。