python开发中,两个文件之间的内容切换

from sys import argv
from os.path import exists
# import exists。这个命令将文件名字符串作为参数,如果文件存在的话,它将返回True,否则将返回 False
script,from_file,to_file = argv
print("Copying from %s to %s"%(from_file,to_file))

in_file = open(from_file)
indata = in_file.read()

print("The input file is %d bytes long"%len(indata))

print("Does the output file exist? %r" % exists(to_file))
print("Ready,hit RETURN to continue,CTRL-C to abort.")
input()

out_file = open(to_file,'w')
out_file.write(indata)

print("Alright,all done")

out_file.close()

in_file.close()


以上运行输入两个参数: 文件1所在的路径  文件2所在的路径

猜你喜欢

转载自blog.csdn.net/whjay520/article/details/64918481