[Tutor] howto mysqldb dictionary cursor

Vaibhav.bhawsar whatpot at gmail.com
Fri Apr 25 05:17:15 CEST 2008


I have been trying to get the DictCursor working with mysqldb module but
can't seem to. I have pasted the basic connection code and the traceback
from pydev. The connection does open with the default cursor class. can't
figure out how to use the dict cursor class instead of the default one. many
thanks.

<code>
import MySQLdb
import sys
# connect to the MySQL server
try:
    conn = MySQLdb.connect(host="localhost
",read_default_file='~/.my.cnf',db='test',cursorclass=MySQLdb.cursors.DictCursor)
    cur = conn.cursor()
    print conn
except MySQLdb.Error, e:
    print "Error %d: %s" % (e.args[0], e.args[1])
    sys.exit (1)
</code>

Traceback (most recent call last):
  File "/Users/.....src/db/test.py", line 7, in ?
    conn =
MySQLdb.connect(host="localhost",read_default_file='~/.my.cnf',db='te
st',cursorclass=MySQLdb.cursors.DictCursor)
AttributeError: 'module' object has no attribute 'cursors'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080424/072e83fb/attachment.htm>


More information about the Tutor mailing list