Hi,
First off, I'm a real greenhorn so please forgive me asking questions which may be bleeding obvious, but I have searched and searched and cannot find an answer to my problem.
I'm trying to import a CSV file into sqlite3 database in python. The CSV file has 56 columns though. Is there any way to create the sqlite table columns without having to manually describe each column
eg con.execute("CREATE TABLE IF NOT EXISTS QUESTIONS (col1, col2.... )")
I imagine there must by a simple way of taking the first row of the csv file and using those comma-seperated values to define the columns of the table. Please tell me I don't have to manually define all 56 table columns!!!
In my searching I have found methods for assigning the values of the first row to describe table columns but not creating the columns and naming them at the same time.
Also, if such a method exists can it handle column descriptors which are strings ie defined within ""s? (A number of these column names are longish sentences)

The SQL statement is string, so you can probably do something like:

num_title=54
headerline=','.join("Header%i" %i for i in range(num_title)) ## take in reality from header
sql="CREATE TABLE IF NOT EXISTS (%s)" % headerline
print sql

Edited 6 Years Ago by pyTony: n/a

This question has already been answered. Start a new discussion instead.