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

您正在从此处的键中删除两个字符,这就是它不再与表中的键匹配的原因:

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