public marks

PUBLIC MARKS with tags recipe & sql

05 October 2005 16:45

ASPN : Python Cookbook : List comprehensions for database requests

by roberto
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

PUBLIC TAGS related to tag recipe

python +   sql +  

Active users

roberto
last mark : 05/10/2005 16:46