您的位置:首页 > 编程语言 > Python开发

Python 拷贝文件

2015-05-04 20:10 267 查看
使用Python拷贝文件到另一个文件中。

1、copy.py

#coding:utf-8
import os
from sys import argv

script,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中了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: