' sqlite3.Cursor'对象不可调用

时间:2018-05-28 18:02:52

标签: python sqlite

我尝试将Python与SQLite连接并为其创建GUI。所以这里有一些代码:

db_name = 'database.db'
def run_query(self, query, parameters =()):
    with sqlite3.connect (self.db_name) as conn:
         cursor = conn.cursor()
         query_result = cursor.execute (query, parameters)
         conn.commit()
    return query_result()




def viewing_records (self):
    records = self.tree.get_children()
    for element in records:
        self.tree.delete (element)
    query = 'SELECT * FROM product ORDER BY name DESC'
    db_rows = self.run_query (query)
    for row in db_rows:
        self.tree.insert('', 0, text = row[1], values = row[2])

问题是当我运行self.viewing_records()时出现以下错误' sqlite3.Cursor'对象不可调用。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

return query_result()尝试在游标对象上使用调用(())。只需返回光标而不调用

return query_result