Created
August 26, 2014 07:35
-
-
Save peerax/5f59af515eb716793b40 to your computer and use it in GitHub Desktop.
python import txt,csv to sqlite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv, sqlite3 | |
conn = sqlite3.connect("converting2.sqlite") | |
curs = conn.cursor() | |
curs.execute("CREATE TABLE document (col1 TEXT, col2 TEXT, col3 TEXT, col4 TEXT,col5 TEXT);") | |
reader = csv.reader(open('Calendar.txt', 'rU'), delimiter=' ') | |
for row in reader: | |
to_db = [unicode(row[0], "utf8"), unicode(row[1], "utf8"), unicode(row[2], "utf8"), unicode(row[3], "utf8"), unicode(row[4], "utf8")] | |
curs.execute("INSERT INTO document VALUES (?, ?, ?,?,?);", to_db) | |
conn.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment