def LoadFile(f, table_name, conn):
  reader = csv.reader(f)
  header = reader.next()

  columns = []
  for n in header:
    n = n.replace(' ', '')
    n = n.replace('-', '_')
    columns.append(n)

  create_columns = []
  column_types = {}
  for n in columns:
    if n in column_types:
      create_columns.append("%s %s" % (n, column_types[n]))
    else:
      create_columns.append("%s INTEGER" % (n))

  c = conn.cursor()
  try:
    c.execute("CREATE TABLE %s (%s)" % (table_name, ",".join(create_columns)))
  except sqlite.OperationalError:
    # Likely table exists
    print "table %s already exists?" % (table_name)
    for create_column in create_columns:
      try:
        c.execute("ALTER TABLE %s ADD COLUMN %s" % (table_name, create_column))
      except sqlite.OperationalError:
        # Likely it already exists
        print "column %s already exists in %s?" % (create_column, table_name)

  placeholders = ",".join(["?"] * len(columns))
  insert_values = "INSERT INTO %s (%s) VALUES (%s)" % (table_name, ",".join(columns), placeholders)

  #c.execute("BEGIN TRANSACTION;")
  for row in reader:
    if row:
      if len(row) < len(columns):
        row.extend([None] * (len(columns) - len(row)))
      c.execute(insert_values, row)
  #c.execute("END TRANSACTION;")
  conn.commit()
remove_duplicates([2,2,2,1,3,3]) => [3,1,2]
dataset/ETHPy150Open google/transitfeed/misc/sql_loop.py/LoadFile--crossover with--dataset/ETHPy150Open kleientertainment/ds_mod_tools/pkg/win32/Python27/Lib/SimpleXMLRPCServer.py/remove_duplicates