[Twisted-Python] How to properly return a dict from adbapi
itamar at itamarst.org
Mon Feb 19 21:51:36 EST 2007
On Mon, 2007-02-19 at 16:39 +0100, "Einar S. Idsø" wrote:
> 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 for d in self._cursor.description]
> return [dict(zip(columns, r)) for r in result]
Some database adapters will return objects that act like dictionaries,
or have an extra method that does so. adabpi itself doesn't really
provide any extra infrastructure for doing so since it's intended as a
thin layer wrapping db-api.
More information about the Twisted-Python