'builtin_function_or_method' object has no attribute 'execute' for cursor.ececute(statement) [closed]

半城伤御伤魂 提交于 2019-12-23 20:23:37

问题


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?


回答1:


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()


来源:https://stackoverflow.com/questions/45348210/builtin-function-or-method-object-has-no-attribute-execute-for-cursor-ececut

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!