MySQLdb can't use cursorclass
I am trying t开发者_开发百科o execute the following code:
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()
But it gives me the following error:
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'
Why is this?
import MySQLdb
import MySQLdb.cursors
conn=MySQLdb.connect(host = '127.0.0.1',
user = 'root',
passwd = 'root',
db = 'test',)
cursor=conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
This is a rough hack, but it may not be advisable to use it. The script with throw out dictionary object by default but the application might require an tuple or array.
精彩评论