module for working with the result set
Paul McNett
p at ulmcnett.com
Mon May 17 21:20:42 EDT 2004
john fabiani writes:
> following your thoughts on the keys and my mistake - can you
> tell me how to get into a dict format?
For MySQL, there is the DictCursor class. Here's an example,
and you should even be able to use it as-is as I've opened up
public access to my MySQL database:
>>> import MySQLdb.cursors
>>> conn = MySQLdb.connect(host='melder.paulmcnett.com', user='dabo', passwd='dabo', db='dabotest')
>>> dictCursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)
>>> print dictCursor.execute('select * from recipes where mingred like "%coriander%"')
14
>>> recordSet = dictCursor.fetchall()
>>> for record in recordSet:
... print record['iid'], record['ctitle']
...
184 Cucumber Salad
186 Garlic Shrimps
193 Chinese Salad with Crispy Won Tons
299 Chicken Curry
304 Kai Phat Khing
305 Kung Tom Yam
306 Ma Ho
308 Yam Krachup
332 Lentil Soup
817 Mixed Vegetable Curry
841 Thai Mushroom Soup
843 Rice Noodle Salad with Ginger
915 Santa Fe Stew
966 Mixed Potato Soup
--
Paul
http://www.paulmcnett.com
More information about the Python-list
mailing list