Python and SQLite: insert into table -


i have list has 3 rows each representing table row:

>>> print list [laks,444,m] [kam,445,m] [kam,445,m] 

how insert list table?

my table structure is:

 tablename(name varchar[100], age int, sex char[1]) 

or should use other list?

here actual code part:

    record in self.server:         print "--->",record         t=record         self.cursor.execute("insert server(server) values (?)",(t[0],));         self.cursor.execute("insert server(id) values (?)",(t[1],))         self.cursor.execute("insert server(status) values (?)",(t[2],)); 

inserting 3 fields separately works, using single line like

self.cursor.execute("insert server(server,c_id,status) values (?,?,?)",(t[0],),(t[1],),(t[2],))

or

self.cursor.execute("insert server(server,c_id,status) values (?,?,?)",(t),)

does not.

conn = sqlite3.connect('/path/to/your/sqlite_file.db') c = conn.cursor() item in my_list:   c.execute('insert tablename values (?,?,?)', item) 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -