Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 在python循环的每次迭代中创建一个文本文件_C_Python 3.7 - Fatal编程技术网

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

我有一个运行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()

它以一个文本文件作为输入,创建一个文本文件作为输出,我想做一个循环,在每次迭代中创建一个文本文件,而不替换上一个。我该怎么做

在open函数调用中为append添加a

outFile = open("/Users/stordd/Desktop/StageI2M/Leiden/text_file/Output.txt", 'ab')

多谢各位!只是有一点修正,它只是'ab',因为我有一个错误:>ValueError:必须正好有一个create/read/write/append模式