I have seen a few of these errors on Stackoverflow but non of the answers seem to be working when I implement them.
import csv, sqlite, sys
conn = sqlite.connect('Database_Practice.db')
mouse = conn.cursor()
input = open('DATA.csv','rb')
my_reader = csv.reader(input, delimiter = ',',quotechar='|')
mouse.execute("DROP TABLE IF EXISTS Example_Input;")
mouse.execute("CREATE TABLE Example_Input (ID INTEGER, Name VARCHAR, Job VARCHAR, Salary INTEGER);")
try:
to_database = [entry for entry in my_reader]
for block in to_database:
mouse.execute("INSERT INTO Example_Input (ID,Name,Job,Salary) VALUES (?,?,?,?)", block)
finally:
conn.commit()
input.close()
I know the variable is getting the variables, as if I comment out the INSERT line I get the output:
['1', 'Billy', 'Tech', '888']
['2', 'Jane', 'Sales', '777']
['3', 'Scott', 'Tech', '667']
['4', 'Harris', 'Tech', '444']
['5', 'Gray Skull', 'Sales', '333']
['6', 'Barbarosa', 'Assistant', '200']
['7', 'Nick', 'Janitor', '100']
but after a long time of trying to tweak it, I can't seem to get it to stop giving me the error:
File "Another_Try.py", line 18, in ?
mouse.execute("INSERT INTO Example_Input (ID,Name,Job,Salary) VALUES (?,?,?,?)", block[0:4])
File "/usr/lib64/python2.4/site-packages/sqlite/main.py", line 255, in execute
self.rs = self.con.db.execute(SQL % parms)
TypeError: not all arguments converted during string formatting
Any advice?
EDIT:
try:
to_database = [entry for entry in my_reader]
for block in to_database:
# mouse.execute("INSERT INTO Example_Input (ID,Name,Job,Salary) VALUES (?,?,?,?)", block)
print block