# file formatter for csv files import os ctr = 6 cctr = 0 for f in os.listdir('to import'): print 'Processing file %s' % f with open('to import/' + f, 'r') as h: with open('export/' + f, 'w') as ex: if f.endswith('electricityrates.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): if not line.startswith(',') and not line == str(): ex.write(str(ctr) + ',' + line[0:-4] + '\n') #skip the last comma elif f.endswith('FuelPrice.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): ex.write(str(ctr) + ',' + line) elif f.endswith('ListOfHours.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): ex.write(str(ctr) + ',' + line) elif f.endswith('monthlydemandrates.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): if not line.startswith(',') and not line == str(): ex.write(str(ctr) + ',' + line) elif f.endswith('MonthlyFee.csv'): cctr += 1 for line in h.readlines(): ex.write(str(ctr) + ',' + line) elif f.endswith('monthseason.csv'): cctr += 1 # skip the first line h.readline() for line in h.readlines(): ex.write(str(ctr) + ',' + line) if cctr % 6 == 0: ctr += 1