I am trying to write the output of several subprocess python program to a same file. The main python program looks like this:
forums = ["f20","e70","x3","e89","series7","m5","f10","series6","z4e85","i3i8","f22","f80","f15","f48","f87"]
for f in forums:
command = "python 01-measurevariation.py "+ f+"-commoncrawl-timestamp.csv-excludeunif"
print command
exit_status = subprocess.call(command, shell=True)
And the subprocess python program 01-measurevariation.py is here(showing only related codes):
input_file= str(sys.argv[1])
output_file = "tsvariations.csv"
...
with open(input_file) as to_read:
with open(output_file, "wb") as tmp_file:
reader = csv.reader(to_read, delimiter = ",")
writer = csv.writer(tmp_file)
....
writer.writerow (["variance of "+sys.argv[1]+" is "+"%.2f" % numpy.var(difflist)+ " hours"])
writer.writerow (["std of "+sys.argv[1]+" is "+ "%.2f" % numpy.std(difflist) +" hours"])
However, the output file "tsvariations.csv" only contains 2 lines, which is the output of the last subprocess in the for loop in the main python program.
I want the tsvariations.csv to contain all subprocess output, which should have a total of 30 lines. (2 lines for each of the 15 entries in "forums" list). How can I do that? Thanks.