python - 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'
解决方案
您需要调用游标函数。所以替换cursor=mycon.cursor
为cursor=mycon.cursor()
推荐阅读
- windows - 在没有管理员权限的情况下使用 Windows Update API (WUApiLib)
- javascript - 刷新后将拖动的项目反应到原始位置
- c# - 在 WinForm 中的面板内创建垂直线
- vba - 在文件夹中打开、复制、粘贴关闭和循环文件
- pyspark - PySpark Iterator[pd.Series] UDF 中的输入列如何拆分成块?
- python - python中是否有一种方法可以通过在列上应用条件将 series.str 转换为标题大小写
- java - 为什么它在 google kickstart 2021 轮 A 测试 2 中出现运行时错误
- string - 使用 Open Weather Map 每小时数据
- python - 要绘制的时间序列数据
- python - “ModuleNotFoundError:没有名为‘tgan’的模块”