I have looked through the 'similar questions' here and didn't see one that was close.
I have a text file and headers that I write in Python, but when I open and then write data to the file it starts off immediately after the header, when I want the data to start on the line immediately under the header. I looked at some suggestions here and it said to use the lineterminator argument but that hasn't fixed anything so I think I must be misusing it?
What I try:
import csv
results_file_path = ("C:\\Users\\priper\\Desktop\\freq_sweep_results\\headers_01.txt")
with open(results_file_path, 'w', newline='') as filey:
csv_writer = csv.writer(filey, delimiter = '\t', lineterminator='\n')
csv_writer.writerow(['Freq', 'a1','b1','c1'])
filey.close()
frequency = 1000
a1_results = [6.2]
b1_results = [9.9]
c1_results = [90.0]
with open(results_file_path, 'a', newline='') as filey:
csv_writer = csv.writer(filey, delimiter = '\t', lineterminator='\n')
csv_writer.writerow([frequency, a1_results[-1], b1_results[-1], c1_results[-1] ])
text file results:
Freq a1 b1 c11000 6.2 9.9 90.0
desired text file results:
Freq a1 b1 c1
1000 6.2 9.9 90.0
Any ideas?