I am trying to export my output to a list. Here is my code:
import csv
import numpy as np
row_list = np.arange(0,5)
for row in row_list:
a = row + 3
b = row + 4
c = row + 5
result = [a, b, c]
csvfile = "/home/Desktop/test"
with open(csvfile, "w") as output:
writer = csv.writer(output, lineterminator='\t')
for val in result:
writer.writerow([val])
I run the code, a test file is created on my desktop (which is exactly what I want) but the data in the file is wrong.
The output is:
7 8 9
But this is not what I want. The script is running through the loop but it's only exporting the last line. Any ideas on how to get it to export the data in the file in the following manner:
3 4 5
4 5 6
5 6 7
6 7 8
7 8 9
Thanks!
EDIT: What if I want to give this script to my professor. The directory /home/paula/Desktop/test does not exist on her laptop. I tried to write csvfile = "~/Desktop/test" but it gave me an error. Any idea?
Note: I am using ubuntu 12.04.