October 2005
![](http://blogmarks.net/screenshots/2005/10/05/52fb0151a0c99d9018f05367f1df15b5.png)
ASPN : Python Cookbook : List comprehensions for database requests
The usual way to make a request to a database is to write a string with the SQL syntax, then execute this request and get the result as a list with cursor.fetchall() or cursor.fetchone()
Python has list comprehensions to select items in an iterable if a certain condition is true ; this is very similar to database requests
This recipe wraps a table of a DB-API compliant database in a class that implements the iteration protocol, so that you can use the for ... in ... if ... syntax
September 2004
Ian Bicking 6.9.2004
Beautiful.
March 2004
ezSqlObject
A convenience wrapper for SQLObject.
1
(3 marks)