Hi I'm using SQlite and the CSV module and trying to create a class
that converts data from CSV file into a SQLite table.
My script curently uses functions for everything and I'm trying to
improve my class programming. The problem I'm having is with variable
expansion.
self.cursor.exe cutemany('INSER T INTO test VALUES (?)', CSVinput)
If CSVinput is a tuple with only 1 value, everything is fine. If I
want to use a tuple with more than 1 value, I need to add more
question marks. As I'm writing a class I don't want to hard code a
specific number of ?s into the INSERT statement.
The two solutions I can think of are;
using python subsitution to create a number of question marks, but
this seems very dirty
or
finding someway to substitue tuples or lists into the statement - I'm
not sure if this should be done using Python or SQLite substitution
though.
Any tips on where to start looking?
Thanks, Marc.
that converts data from CSV file into a SQLite table.
My script curently uses functions for everything and I'm trying to
improve my class programming. The problem I'm having is with variable
expansion.
self.cursor.exe cutemany('INSER T INTO test VALUES (?)', CSVinput)
If CSVinput is a tuple with only 1 value, everything is fine. If I
want to use a tuple with more than 1 value, I need to add more
question marks. As I'm writing a class I don't want to hard code a
specific number of ?s into the INSERT statement.
The two solutions I can think of are;
using python subsitution to create a number of question marks, but
this seems very dirty
or
finding someway to substitue tuples or lists into the statement - I'm
not sure if this should be done using Python or SQLite substitution
though.
Any tips on where to start looking?
Thanks, Marc.
Comment