pythonsqlitedatabase-cursor

'builtin_function_or_method' object has no attribute 'execute' for cursor.execute(statement)


c = sqlite3.connect(history_db)
cursor = c.cursor

select_statement = "SELECT urls.urls,urls.Visit_count FROM urls,Visits WHERE 
urls.id=visits.urls;"
cursor.execute(select_statement)

results = c.cursor.fetchcall()

print(results)

The code above when executed gives an error something like

Traceback (most recent call last):
File "test.py", line 13, in <module>
cursor.execute(select_statement)
AttributeError: 'builtin_function_or_method' object has no attribute 
'execute'

I am new to using python sqlite3 so how do I execute this query with sqlite3 in python?


Solution

  • Connection.cursor is a method, if you don't call it you get the method object itself, not the result of calling it. IOW, what you want is

    cursor = c.cursor()