Basically what I'm looking to do in Python 3.2 is read the input csv file which contain 3 columns then create an sql output file, where the 3 data in each line from the input file, will be as parameters in an insert query :
My code looks like this :
import os
import csv
InFileName = r'path\test.csv'
OutFileName = r'path\test.sql'
NumCommas = 0
File = open(InFileName)
for line in File:
if line.count(',') > NumCommas:
NumCommas = line.count(',')
File.seek(0)
reader = csv.reader(File)
OutFile = open(OutFileName, 'w')
for rows in reader:
OutFile.write("insert into table_name values(",rows[0],", 2, to_date(", rows[1],",'YYYY-MM-DD'), 1, 1, -1, 0, ",rows[2],", ",rows[2],", 0, 0, 0, sysdate, 0);" + '\n')
OutFile.close()
File.close()
I got the error:
list index out of range