title: Automatically Load SQL table by reading data from text file
body: <p>I am trying to write a python script that is going to load the tables that I created in pyhton using SQL and populate them with data automatically that is coming from a text file.  I am stuck on basic coding. I do have a general idea but I am getting errors when I try to run this approach. I have created 2 tables. I have read the file. the file is a comma seperated text file with no headers. </p>
  
  <p>first 3 lines of the file looks like this. </p>
  
  <pre><code>+ ---- + ----- + -------------------- + -------- + - + --- + ----- +
  | John | Smith | 111 N. Wabash Avenue | plumber  | 5 | 1.0 | 200   |
  | John | Smith | 111 N. Wabash Avenue | bouncer  | 5 | 1.0 | 200   |
  | Jane | Doe   | 243 S. Wabash Avenue | waitress | 1 | 5.0 | 10000 |
  + ---- + ----- + -------------------- + -------- + - + --- + ----- +
  
  import sqlite3
  conn= sqlite3.connect('csc455.db')
  c = conn.cursor()
  
  #Reading the data file
  fd = open ('C:/Users/nasia/Documents/data_hw2.txt','r')
  data = fd.readlines()
  
  #Creating Tables
  &gt;&gt;&gt; L = """create table L
  ... (first text, last text, address text, job text, LNum integer,
  ... constraint L_pk
  ... primary key(first, last, address, job),
  ... constraint L_fk
  ... foreign key (LNum) references LN(LNum)
  ... );"""
  &gt;&gt;&gt; c.execute(L)
  
  LN = """create table LN
  ... (
  ... LNum integer, Interest float, Amount, Integer,
  ... constraint LN_pk
   ... primary key (LNum)
  ... );"""
   c.execute(LN)
  
  #Inserting into database
  for elt in data:
  ...     currentRow = elt.split(", ")[:-1]
  ...     insert = """(insert into LN values (%s, %s, %s);, %(currentRow[4], currentRow[5], currentRow[6]))"""
  ...     c.execute(insert)
  </code></pre>
  
  <p>There is some syntax error here. The code stops working. I cannot figure out what I am doing wrong. 
  The error is
      Traceback (most recent call last):
        File "", line 4, in 
      OperationalError: near "(": syntax error</p>
  
  <p>I can not figure out what am I doing wrong</p>