1

私は 3 時間を失いましたが、何が間違っているのかわかりません。助けてください。エラーが発生しないため、更新ステートメントで必要なキーを渡さないという結論に達しましたが、データベースも更新されません。

conn = sqlite3.connect('mov.db')
c = conn.cursor()
old_rows = c.execute('SELECT imdb FROM movies WHERE desc="" and imdb<>"" and year<"1997"')
result = c.fetchall()

for row in result:
    key = row[0] [2:]
    try:
    # Get a Movie object with the data about the movie identified by
    # the given movieID.
        movie = i.get_movie(key)
    except IMDbError, e:
        print "Probably you're not connected to Internet.  Complete error report:"
        print e
            continue

    print movie['title']
    if movie.has_key('plot outline'):
    m=movie['plot outline']
    print m
    print key
    c.execute('UPDATE movies SET desc=? WHERE imdb=?',(m,key))
    print c.rowcount

# Commit the changes and close everything.
conn.commit()
c.close()
conn.close()
4

2 に答える 2

0

continue反復ごとに発生するように見えるため、行c.execute('UPDATE ...が実行されることはありません。コードが適切にインデントされていますか?

于 2012-05-07T06:19:45.697 に答える
0

ここでキーから 2 文字を切り取っているため、テーブルのキーと一致しなくなりました。

key = row[0] [2:]
于 2012-05-07T06:45:29.853 に答える