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()
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所在的路径