|
from sys import argv
from os.path import exists
script,from_file,to_file=argv
print(f'coping from{from_file}to{to_file}')
indata=open(from_file).read()
print(f'the input file is {len(indata)} bytes long')
print(f'does the output file exist? {exists(to_file)}')
print('ready,hit return to continue')
open(to_file,'w').write(indata)
print('alright all done')
open(to_file,'w').close()
open(from_file).close()
这个程序运行的结果虽然能够创建一个新的文件,但是新文件中的内容为空。但是当我删除open(to_file,'w').close()这句代码时,新文件里面出现了想写入的内容,请问是为什么
|
|