Still teaching myself python so please don’t hate me if my code is terrible…
My code:
ifile = csv.reader(open("TE.csv",'rb'))
shutil.copy("TE.csv","temp")
tempfile = csv.reader(open("temp","rb"))
ofile = csv.writer(open("TE-RESULTS.csv","ab"))
for row in ifile:
#do some web scraping stuff here
VC_s = str(cells[1].find(text=True))
VC_i = str(cells[2].find(text=True))
VT_s = str(cells[4].find(text=True))
entry = [VC_s, VC_i, VT_s]
rowAdd = tempfile.next()
ofile.writerow(rowAdd + entry)
Problem: I start with a CSV that I will have to add 3 columns to the end. Using my code above, I get the following output:
HEADER1 HEADER2 HEADER3 result1 result2 result3
autocheck C:\check 1.jpg result1 result2 result3
services C:\svcs 2.jpg result1 result2 result3
My DESIRED output:
HEADER1 HEADER2 HEADER3 HEADER4 HEADER5 HEADER6
autocheck C:\check 1.jpg result1 result2 result3
services C:\svcs 2.jpg result1 result2 result3
What is the best way to fix my code that will give me the desired output? My initial thought would be to delete the HEADERS row and replace it with a new HEADERS row in the TE-RESULTS.csv file.
Process the header row before the for loop.