I am trying to use sqlite3 in Python by using a for loop to iterate through all the items in a list and populate a column with that data. My code below will hopefully shed some light on the problem:
import sqlite3 as lite
test_run = ['tommy', 'olga', 'peter', 'lulu']
con = lite.connect("test.db")
cur = con.cursor()
cur.execute('DROP TABLE IF EXISTS test1;')
cur.execute('CREATE TABLE test1(symbol TEXT); ')
for i in test_run:
name = i
print name
cur.executemany('INSERT INTO test1 VALUES(?)',name)
with con:
cur = con.cursor()
cur.execute("SELECT * FROM test1")
rows = cur.fetchall()
for row in rows:
print row
I apologize if this is very basic, but I have just learned Python and this is my first time using SQL. When I print name it seems like this should work but when using fetchall to see what is being populated it appears as:
(u't',)
(u'o',)
(u'm',)
(u'm',)
(u'y',)
(u'o',)
(u'l',)
I have read a lot of the answers here and this would seem to be the correct way to accomplish this.