How to write VALUES statement in a insert statement in Python?🙄
Creating a script where I am reading from csv file and iterating all the rows in the csv file but i need help to generate insert statements of each row and I am also output it that into a file. So my only issue is the generate insert statements of each row. Thanks for the help. ------------------------------------------------------------------------ here is my code: ------------------------------------------------------------------------ import csv openFile = open('data.csv', 'r') csvFile = csv.reader(openFile) header = next(csvFile) headers = map((lambda x: '"' + x + '"'), header) insert = 'INSERT INTO my_table (' + ", ".join(headers) + ") VALUES " values = [] for row in csvFile: #this line below values.append('(' + ','.join(map(lambda x: '"%s"' % x, row)) + ')') data = insert + ("".join(values)) print(data) createOnFile = open("data.txt","w+") createOnFile.write(data) createOnFile.close() openFile.close() -------------------------------------------------------------------- Thanks for the help.