I have a large collection of DAT files that need to be converted (eventually to a unique file type). The DAT\'s have a mixed amount of whitespace between fields, and the column
Treat those header lines in the input file with all the disdain they deserve. (Or, in other words, read them and discard them.)
headers='Year Month Day Hour Minute Direct Diffuse2 D_Global D_IR U_Global U_IR Zenith'
with open ( 'temp.dat') as input_file:
with open ('temp_2.csv', 'w') as output_file:
output_file.write('"%s"\n'%'","'.join(headers.split()))
for count, line in enumerate(input_file):
if count<4: continue
outLine = ','.join(line.split())
output_file.write(outLine + '\n')