【发布时间】:2017-11-22 04:55:12
【问题描述】:
我有以下简单的代码来测试我的 Python Mysql 连接。
connection = pymysql.connect(host = "localhost",
user = "root",
passwd = "",
db = "bugs",
charset = "utf8mb4",
cursorclass = "pymysql.cursors.Dictcursor")
try:
with connection.cursor() as cur:
cur.execute('''SELECT COUNT(*) FROM tbl_firefox''')
for row in cur.fetchall():
print("Number of rows in firefox table:", row)
connection.commit()
finally:
connection.close()
运行代码时出现类型错误
File "test2.py", line 31, in <module>
with connection.cursor() as cur:
File "C:\Program Files\Anaconda3\lib\site-packages\pymysql\connections.py", line 833, in cursor
return self.cursorclass(self)
TypeError: 'str' object is not callable
我一直在其他 python-mysql 代码中查看类似的错误。但仍然没有运气。如果有人能指出我的错误,非常感谢。
【问题讨论】:
标签: mysql python-3.x pymysql