使用简单的sqlite查询在python中令人困惑的AttributeError
发布时间:2020-12-12 19:07:18 所属栏目:百科 来源:网络整理
导读:当我在 python中调用一个函数来执行查询时,我遇到的错误令我感到困惑和沮丧.我已经检查过以确保我没有标签而不是间隔缩进(检查不明确).我遵循了这里使用的惯例: http://zetcode.com/db/sqlitepythontutorial/和这里: How to check the existence of a row
当我在
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()(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |