Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Baffling AttributeError in python with simple sqlite query

Tags:

python

sqlite

I'm baffled and frustrated by an error I'm getting when I call a function in python to execute a query. I have checked to make sure I don't have tabs instead of spaced indents (checking the obscure). I've followed the convention used here: http://zetcode.com/db/sqlitepythontutorial/ and here: How to check the existence of a row in SQLite with Python?

Can anyone see why this seemingly-good code would throw an error? I'm codeblind right 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 a loop, later on, and is being passed data properly. I stuck a print line in the function to make sure data was being passed properly and got this, which is right.

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

I've run the same, exact query in sqlite directly on the same db and results come back as expected.

like image 725
Todd Curry Avatar asked Apr 22 '13 15:04

Todd Curry


1 Answers

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

like image 185
sberry Avatar answered Oct 05 '22 23:10

sberry