· 8 years ago · Aug 23, 2018, 09:20 PM
1create table using python objects
2import sqlite3
3conn = sqlite3.connect('./foo.sql')
4c = conn.cursor()
5for line in file:
6 if line[0] == 'firstline':
7 # Below is the line in question
8 c.execute(""" create table if not exists bar(?, ? ,?); """, lineTuple)
9 else:
10 c.execute(""" insert into bar values (?, ?, ?); """, lineTuple)
11
12import csv
13file_ptr = open('filename.csv','r');
14fields = range(0, total number of columns in file header)
15file_data = csv.DictReader(file_ptr, fields, delimiter=',')
16for data in file_data:
17 print data
18 # data will be in dict format and first line would be all your headers,else are column data
19 # here, database query and code processing