Baffling AttributeError in python with a simple SQL query

I am puzzled and disappointed with the error I get when I call a function in python to execute a request. I checked that I did not have tabs instead of indentation (ambiguity check). I followed the convention used here: http://zetcode.com/db/sqlitepythontutorial/ and here: How to check if a string exists in SQLite with Python?

Can anyone understand why this seemingly good code will cause an error? I'm blind now. Thanks!

Error:

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' 

Relevant Code:

 #!/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); 

This function is called from the loop later and passes the data correctly. I was stuck in the print function to make sure the data was transferred correctly and received it that is correct.

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

I ran the same exact query in sqlite right on the same db and the results will return as expected.

+6
source share
1 answer

I believe that cur1 = con1.cursor should be cur1 = con1.cursor()

+17
source

All Articles