使用简单的sqlite查询在python中令人困惑的AttributeError

前端之家收集整理的这篇文章主要介绍了使用简单的sqlite查询在python中令人困惑的AttributeError前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我在 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中运行相同的确切查询,结果按预期返回.

我相信cur1 = con1.cursor应该是cur1 = con1.cursor()
原文链接:https://www.f2er.com/sqlite/197677.html

猜你在找的Sqlite相关文章