In [26]:
import csv
with open("SAM_PUBLIC_MONTHLY_20170604.dat", "r") as input_file:
with open("output.csv", "w") as output_file:
with open("sam_header.txt", "r") as header_file:
header = header_file.read() #Read the header from a file
output_file.write(header) #Write the header to the output
print(input_file.readline()) #Discard the first line of the input
csv.writer(output_file, delimiter=',').writerows(csv.reader(input_file, delimiter='|')) #Process file