I know this question has been asked quite a few times but I cannot seem to get any of the ways described working.
I am trying to import a file to a database the file has columns of data seperated by a comma (i.e. csv). I have made a test file that resembles my actula file I would like to read in so here is the contents.
Wind_Speed, Wind_Direction, Wind_Max
10, 360, 12
13, 320, 11
12, 340, 14
12, 360, 14
Here is what I have been doing already.
#!/usr/bin/python3.3
import csv, sqlite3
con = sqlite3.connect('test.db')
cur = con.cursor()
with open('test.dat', newline='') as f:
reader = csv.reader(f)
for column in reader:
cur.execute('INSERT INTO jaws VALUES {}'.format(column))
con.commit()
And here is the error message,
Traceback (most recent call last):
File "csvdict.py", line 11, in <module>
cur.execute('INSERT INTO jaws VALUES {}'.format(column))
sqlite3.OperationalError: near "['Wind_Speed', ' Wind_Direction', ' Wind_Max']": syntax error
I am sure I am being stupid and missing something obvious but I can't see it.
Thanks