Hi tutors, I've got a functions that should update an sqlite database, among other things. However the database doesn't get updated. When used in isolation, the update statement works fine. What am I doing wrong?
Below is the function. The whole script can be found at http://pastebin.com/m53978ffa def update_DB_chi_square(): global stopwords conn = sqlite3.connect(os.path.join('.', 'collocations_base.sqlite')) c = conn.cursor() c.execute('select * from word_couples') couples_and_nbrs = c.fetchall() for couple_and_nbr in couples_and_nbrs: w1, w2, o11, chi_square = couple_and_nbr if o11 < 5 or w1 in stopwords or w2 in stopwords: continue o12 = c.execute("""select sum(nbr_occ) from word_couples where w1 = ? and w2 != ? """, (w1, w2)).fetchall()[0][0] or 0 o21 = c.execute("""select sum(nbr_occ) from word_couples where w1 != ? and w2 = ? """, (w1, w2)).fetchall()[0][0] or 0 o22 = c.execute("""select sum(nbr_occ) from word_couples where w1 != ? and w2 != ? """, (w1, w2)).fetchall()[0][0] or 0 n = c.execute("select sum(nbr_occ) from word_couples").fetchall()[0][0] chi_square = float((n * (o11 * o22 - o12 * o21) ** 2))/ ((o11 + o12) * (o11 + o21) * (o12 + o22) * (o21 + o22)) c.execute('update word_couples set chi_square = ? where w1 = ? and w2 = ?', (chi_square, w1, w2)) print 'check:', '\t'.join((w1, w2, str(chi_square))) c.close() conn.close() Best regards, Emmanuel
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor