说是从一个文件复制到另一个文件,
其实还是读写啦,参考:习题—17
# coding: utf-8
from sys import argv
from os.path import exists
script, from_file, to_file = argv # 将argv解包给script, from_file, to_file三个参数
print ">>>Copying from %s to %s." % (from_file, to_file)
from_txt = open(from_file)
content = from_txt.read()
print "...The file has %s bytes." % len(content) # len()用于查询字符串长度
print ">>>Does the output file exist? %r" % exists(to_file)
print "...If you want to continue, hit Enter, or not, hit Ctrl+C."
raw_input("> ")
to_txt = open(to_file, ‘w‘) # 以‘w‘写的模式打开,原有内容会被清空
to_txt.write(content)
print "Copy has done...and eixt!"
from_txt.close()
to_txt.close() # 有开就有关,记得关闭哦