database in python ?

R. C. James Harlow james at wrong.nu
Mon Apr 11 10:15:50 EDT 2005


On Monday 11 April 2005 11:01, Pierre-Frédéric Caillaud wrote:
> psycopg ... has a dictfetchall() method which is worth its weight in
> donuts ! 

It's very simple to write one for MySQLdb:

def dictfetchall(cursor):
    '''Takes a MySQLdb cursor and returns the rows as dictionaries.'''
    col_names = [ d[0] for d in cursor.description ]
    return [ dict(zip(col_names, row)) for row in cur.fetchall() ]

In truth, although postgres has more features, MySQL is probably better for 
someone who is just starting to use databases to develop for: the chances are 
higher that anyone using their code will have MySQL than Postgres, and they 
aren't going to need the features that Postgresql has that MySQL doesn't. 
IMO, this has changed since only a year or two ago, when MySQL didn't support 
foreign-key constraints.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20050411/f31c7e67/attachment.sig>


More information about the Python-list mailing list