On a weekly basis, I need to replace the header in a csv file (that has a date dependent name) and delete two of the columns. I though the easiest way would be to write a new csv file with the pertinent information(i.e. without columns k and l). This is how my code looks like:
import csv
import calendar
import datetime
from datetime import date, timedelta
today = date.today()
tuesday = date.today() - timedelta(3)
p = tuesday.strftime('%Y%m%d')
us_csv = 'E:/' + "TEST_us_" + p + ".csv"
HIn = "a, b, c, d, e, f, g, h, k, l"
HOut = "A, B, C, D, E, F, G, H"
fIn= open ('us_csv', 'r')
HeaderIn = fIn.readline()
HeaderOut = HeaderIn.replace(HIn, HOut, 1)
fOut = open ('E:/Abase/usStats.csv', 'w')
fOut.write(HeaderOut + '\n')
for line in fIn
fOut.write(line)
fOut.close
The new csv is empty. I read most of the similar questions, but I simply can't figure out how to do this. Any help would be greatly appreciated. Thank you.
fOut.write(line)is not indented further than the for, which means it would execute after the loop completed? Also, is this all of the code or just a relevant snippet?