C 在python循环的每次迭代中创建一个文本文件
我有一个运行C程序的python脚本:C 在python循环的每次迭代中创建一个文本文件,c,python-3.7,C,Python 3.7,我有一个运行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/Deskt
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()
它以一个文本文件作为输入,创建一个文本文件作为输出,我想做一个循环,在每次迭代中创建一个文本文件,而不替换上一个。我该怎么做 在open函数调用中为append添加a
outFile = open("/Users/stordd/Desktop/StageI2M/Leiden/text_file/Output.txt", 'ab')
多谢各位!只是有一点修正,它只是'ab',因为我有一个错误:>ValueError:必须正好有一个create/read/write/append模式