Here's another solution that uses the fact the first argument passed to csv.reader() only has to be somewhat "file-like". This fact means you to could supply an instance of a custom class which changes the double space characters in lines of the file to some other single character (such as a comma). If you do this the header row can be handled like any of the others.
Here's what I'm suggesting:
import csv
class CSV_Translater:
""" File-like object that translates characters. """
def __init__(self, f, old, new):
self.f, self.old, self.new = f, old, new
def __iter__(self):
return self
def __next__(self):
return next(self.f).replace(self.old, self.new)
if __name__ == '__main__':
DELIMITER = ','
filename = "double_whitespace.csv"
with open(filename, 'r', newline='') as file:
translator = CSV_Translater(file, ' ', DELIMITER)
for row in csv.reader(translator, delimiter=DELIMITER):
print(row)
Output
['Day (ddd)', 'N (d)', 'E (d)', 'X (m)', 'Y(s)', 'Z (c)', 'S (p)']
['277', '40.52', '-36.59', '0.11', '-0.50', '-1.62', '30.17']
['277', '40.52', '-36.49', '0.18', '-0.04', '-1.66', '30.14']
['277', '40.51', '-36.39', '0.14', '-0.07', '-1.64', '30.15']