【argv】文件A内容copy到文件B中
作者:互联网
使用脚本,复制start.txt内容,粘贴到end.txt中
from sys import argv from os.path import exists script, from_file, to_file = argv print("Copying from %s to %s." % (from_file, to_file)) # read读取in_file(start.txt)里面的内容 in_file = open(from_file) indata = in_file.read() print("The input file is %d bytes long." % (len(indata))) # 使用exists判断to_file(即没有write权限的end.txt)是否存在 print("Does the output file exist? %r" % exists(to_file)) print("Ready, hit RETURN to continue, CTRL-C to about.") input() # 打开out_file(end.txt),写入indata(start.txt的文本内容) out_file = open(to_file, 'w') out_file.write(indata) print("Alright, all done.") # 关闭in_file(start.txt),out_file(end.txt) out_file.close() in_file.close()
cmd中:
python test.py start.txt end.txt # test.py 为脚本文件,start.txt为初始文件
结果如下:
标签:文件,copy,end,argv,start,file,print,txt,out 来源: https://www.cnblogs.com/sdr900/p/16361717.html