Python 拷贝文件

来源:互联网 发布:双肩女背包 知乎 编辑:程序博客网 时间:2024/05/29 09:16

 使用Python拷贝文件到另一个文件中。

1、copy.py

#coding:utf-8import osfrom sys import argvscript,from_file,to_file = argv#提示print "把文件%s内容拷贝到文件%s中."%(from_file,to_file)#先把from_file打开读取input = open(from_file)inputData = input.read()#判断新文件是否存在print "新文件是否存在:%r" %os.path.exists(to_file)output = open(to_file,'w')#开始写output.write(inputData)#关闭output.close()input.close()

2、命令


3、结果

    这样就把test.txt内容拷贝到test1.txt中了

0 0