[Twisted-Python] How to properly return a dict from adbapi

"Einar S. Idsø" einar.twisted at norsk-esport.no
Mon Feb 19 10:39:54 EST 2007


I am currently using the below technique to return a list of dicts
instead of a tuple of tuples from adbapi. Is there a cleaner way?

def dictQuery(self, query):
   result = self.fetchall()
   columns = [d[0] for d in self._cursor.description]
   return [dict(zip(columns, r)) for r in result]

dbPool = adbapi.ConnectionPool('MySQLdb', db, user, pass, host)
dbPool.runInteraction(dictQuery, "SELECT whatever FROM table"


More information about the Twisted-Python mailing list