我有一个运行C程序的python脚本:
cmd = ["/Users/stordd/Desktop/StageI2M/C/forestenostre/grezza_foresta", "-w", "/Users/stordd/Desktop/StageI2M/Leiden/text_file/USA.txt", "-m", "5", "-e", "-0"]
# Open/Create the output file
outFile = open("/Users/stordd/Desktop/StageI2M/Leiden/text_file/Output.txt", 'wb')
result = subprocess.Popen(cmd, stdout=subprocess.PIPE)
out = result.stdout.read()
outFile.write(out)
outFile.close()
它需要一个文本文件作为输入并创建一个文本文件作为输出,我想创建一个循环,该循环将在每次迭代时创建一个文本文件而不替换上一个。我怎样才能做到这一点 ?
答案 0 :(得分:1)
在打开的函数调用中,添加“ a”作为追加
outFile = open("/Users/stordd/Desktop/StageI2M/Leiden/text_file/Output.txt", 'ab')