kyle k
kyle k

Reputation: 5522

python creating sqlite word dictionary

I am trying to create a database of english words, But no values are being put into the database ,

I am reading each word from a file and using it's sha256 hash to represent the definition of the word, But when i execute the script the database stays the same and is not being filled with the words, the size of the database also stays the same.

Why is the database not being filled with the values?

#!/usr/bin/python
# -*- coding: utf-8 -*-

import sqlite3 as lite
import sys
import hashlib


word_file = open("words.txt", "r")

con = lite.connect('words.db')
cur = con.cursor()  

cur.execute("CREATE TABLE IF NOT EXISTS words(word TEXT PRIMARY KEY, definition  TEXT);")

for word in word_file.read().split():
    cur.execute("INSERT OR REPLACE INTO words VALUES(\"%s\", \"%s\")" % (word, hashlib.sha256(word).hexdigest()))

word_file.close()

# cur.execute("SELECT * FROM words WHERE word = 'hello'")
# print cur.fetchall()
con.close()

Upvotes: 0

Views: 324

Answers (1)

dm03514
dm03514

Reputation: 55972

I believe you have to commit your changes, for your con

http://docs.python.org/2/library/sqlite3.html

Upvotes: 1

Related Questions