1

我无法弄清楚这里的问题是什么。我不断收到的错误代码是“字符串格式化期间参数数量错误”,但我个人没有发现任何问题。谁能指出我正确的方向?谢谢。

def film_function(number, film):
    connection = connect(host='localhost', user='root', \
                                 passwd='', db='survey')
    cursor = connection.cursor()

    sql = "SELECT * FROM persons, persons_films WHERE persons.person = persons_films.person AND number_of_films >= %s AND film = '%s' ORDER BY persons_films.person"

    cursor.execute(sql, [number], [film])
    rows = cursor.fetchall()
    if not rows:
        print ("No one in "+film+" found!")
    else:
        for row in rows:
            print row[0],"-", row[1]
    cursor.close()
    connection.close()
4

1 回答 1

1

这个...

cursor.execute(sql, [number], [film])

应该是这样的:

cursor.execute(sql, [number, film])

您想传递一个参数列表,而不是每个列表都有一个参数。

于 2013-10-16T01:49:59.450 回答