Retrieving column values by column name with MySQLdb

jorma kala jjkk73 at gmail.com
Fri Jun 19 10:46:46 EDT 2009


Hi,
Is there a way of retrieving the value of columns in the rows returned by
fetchall, by column name instead of index on the row?
Code Snippet:

     query="select * from employees"
     db=MySQLdb.connect(host=host,user=user,passwd=passwd,db=database)
     cursor = db.cursor ()
     cursor.execute (query)
     rows = cursor.fetchall ()

      for row in rows:
               print row[0]


Instead of specifying the index of the row to retrieve the first column
(row[0]), I'd like to retrieve the value of the first column by column name.
Something like row.get('employee_id')
Is something of the sort possible with Mysqdb?
Thanks very much.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090619/c1bc540a/attachment.html>


More information about the Python-list mailing list