找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 1699|回复: 0

[求助] 关于复制文件的问题

1

主题

1

帖子

1

积分

贫民

积分
1
chenyicheng 发表于 2018-12-29 14:33:54 | 显示全部楼层 |阅读模式
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()这句代码时,新文件里面出现了想写入的内容,请问是为什么
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表