SQLite查询中的错误

时间:2011-05-27 07:11:01

标签: python sql

我收到此错误:

query() argument 1 must be string or read-only buffer, not tuple. 

我不确定在尝试更改代码后它是什么:

def insert_popularity(Category, filename, cursor):

    txt_file = file(filename, 'r')
    for line in txt_file:
            # Split the line on whitespace
        number, value = line.split()
            # construct the SQL statement
        sql = ("""INSERT INTO popularity (PersonNumber, Category, Value)
                VALUES(%s, %s, %s)""", (number, Category, value))
            # execute the query
        cursor.execute(sql)

connection = MySQLdb.connect(host='localhost', user='root', \
                                 passwd='password', db='dogs')

cursor = connection.cursor()

Category = 'dogs'
insert_popularity(Category, 'dogs.txt', cursor)



connection.commit()

cursor.close()

connection.close()

0 个答案:

没有答案