当我在python中调用一个函数来执行查询时,我遇到的错误令我感到困惑和沮丧。我已经检查过以确保我没有标签而不是间隔缩进(检查不明确)。我遵循了此处使用的惯例:http://zetcode.com/db/sqlitepythontutorial/和此处:How to check the existence of a row in SQLite with Python?
任何人都可以看到为什么这个看起来很好的代码会抛出错误?我现在是代码盲。谢谢!
错误:
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中运行相同的确切查询,结果按预期返回。
答案 0 :(得分:17)
我相信cur1 = con1.cursor
应为cur1 = con1.cursor()