首页 > 解决方案 > Python MySQL AttributeError:'function'对象没有属性'execute'

问题描述

我正在尝试从 Python 上的 MySQL 表中检索数据。但是我收到了

AttributeError: 'function' object has no attribute 'execute'

我的代码是:

import mysql.connector as sqltor
mycon=sqltor.connect(host="localhost",user="root",passwd=" ",database="revision")
if mycon.is_connected():
    print("Successfully Connected to MySQL database.")
else:
    print("Check yo inputs, they really correct?")

cursor=mycon.cursor
cursor.execute("select*from account")

输出:

Successfully Connected to MySQL database.
Traceback (most recent call last):
  File "C:/Users/biina/Documents/Python/Apparel store/Python/Practical File/Interface_Python_with_MySQL.py", line 10, in <module>
    cursor.execute("select*from account")
AttributeError: 'function' object has no attribute 'execute'

标签: pythonattributesexecute

解决方案


您需要调用游标函数。所以替换cursor=mycon.cursorcursor=mycon.cursor()


推荐阅读