“SQLITE3 IMPORT CSV” Réponses codées

csv à sqlite python

import csv, sqlite3

con = sqlite3.connect(":memory:") # change to 'sqlite:///your_filename.db'
cur = con.cursor()
cur.execute("CREATE TABLE t (col1, col2);") # use your column names here

with open('data.csv','r') as fin: # `with` statement available in 2.5+
    # csv.DictReader uses first line in file for column headings by default
    dr = csv.DictReader(fin) # comma is default delimiter
    to_db = [(i['col1'], i['col2']) for i in dr]

cur.executemany("INSERT INTO t (col1, col2) VALUES (?, ?);", to_db)
con.commit()
con.close()
ashattack

SQLITE3 IMPORT CSV

sqlite> .mode csv
sqlite> .import path/to/the/csv/file table_name
Fabrice Hategekimana

Réponses similaires à “SQLITE3 IMPORT CSV”

Questions similaires à “SQLITE3 IMPORT CSV”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code