Python/MySQL

2024-09-28 22:24:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我搞不懂这里有什么问题。我一直得到的错误代码是“错误的参数数量在字符串格式化”,但我个人没有看到任何问题。有人能给我指出正确的方向吗?谢谢。你知道吗

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()

Tags: andinnumberclosesqlconnectioncursorrows
1条回答
网友
1楼 · 发布于 2024-09-28 22:24:41

这个。。。你知道吗

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

应该是这样的:

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

您要传递的是单个参数列表,而不是每个参数都有一个单独的列表。你知道吗

相关问题 更多 >