Python MySQLdb可以';不要使用游标类

Python MySQLdb可以';不要使用游标类,python,mysql-python,Python,Mysql Python,我正在尝试执行以下代码: import MySQLdb import MySQLdb.cursors conn=MySQLdb.connect(host = '127.0.0.1', user = 'root', passwd = 'root', db = 'test', cursorclass = MySQLdb.cursors

我正在尝试执行以下代码:

import MySQLdb
import MySQLdb.cursors
conn=MySQLdb.connect(host = '127.0.0.1',
                     user = 'root',
                     passwd = 'root',
                     db = 'test',
                     cursorclass = MySQLdb.cursors.DictCursor)
cursor=conn.cursor()
但它给了我以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.linux-x86_64/egg/MySQLdb/connections.py", line 243, in cursor
  AttributeError: 'Connection' object has no attribute 'cursorclass'
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
光标中第243行的文件“build/bdist.linux-x86_64/egg/MySQLdb/connections.py”
AttributeError:“Connection”对象没有属性“cursorclass”
为什么会这样?

导入MySQLdb
导入MySQLdb.cursors
conn=MySQLdb.connect(主机='127.0.0.1',
用户='根',
passwd='root',
db=‘测试’,)
cursor=conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)

这是一个粗略的破解,但可能不建议使用它。默认情况下,脚本带有抛出字典对象,但应用程序可能需要一个元组或数组。

您的代码适合我,但我发现路径
build/bdist.linux-x86_64/egg
很奇怪-您是否在生成目录外运行代码?比如说,如果在virtualenv中安装,代码是否有效?