7

当我在 python 中调用函数来执行查询时遇到的错误让我感到困惑和沮丧。我已经检查以确保我没有制表符而不是间隔缩进(检查晦涩难懂)。我遵循了此处使用的约定:http: //zetcode.com/db/sqlitepythontutorial/和此处:如何使用 Python 检查 SQLite 中是否存在一行?

谁能明白为什么这个看似不错的代码会引发错误?我现在是代码盲。谢谢!

错误:

File "paddle-csv-import.py", line 23, in getscore
cur1.execute("SELECT pts FROM matchpoints WHERE s1 =? and s2 = ? and \
AttributeError: 'builtin_function_or_method' object has no attribute 'execute' 

相关代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import numpy as np
import sqlite3 as lite
import trueskill as ts
import sys
import csv
import datetime

#global declarations

# global variables
season = '1011'
unknum = 0

# global functions


def getscore(sets):
    con1 = None
    con1 = lite.connect('match_setup.db')
    cur1 = con1.cursor 
    cur1.execute("SELECT pts FROM matchpoints WHERE s1=? and s2=? and s3=?",(sets))
    homepoints =  cur1.fetchone()
    if homepoints is None:
        print('There is no component named %s'%sets)
    return(homepoints);

稍后从循环中调用此函数,并正确传递数据。我在函数中插入了一条打印线,以确保数据被正确传递并得到了这个,这是正确的。

('3-6', '1-6', '0-0') 

我在同一个数据库上直接在 sqlite 中运行了相同的、精确的查询,结果按预期返回。

4

1 回答 1

17

我相信cur1 = con1.cursor应该是cur1 = con1.cursor()

于 2013-04-22T15:09:54.037 回答