This works for me:
import MySQLdb
db = MySQLdb.connect(host="localhost", user="jon", passwd="jonpass", db="mdbd")
cursor = db.cursor()
date = "1980-06-15"
query = "SELECT firstname, lastname, dob FROM members WHERE dob < %s LIMIT 10"
cursor.execute(query, (date,))
while 1: # next three lines indented
row = cursor.fetchone()
if row is None: break
print "NAME: %s %s; DOB: %s" % (row[0], row[1], row[2])
cursor.close()
If you're not using MySQLdb (and it doesn't look like you are), you should check it out: see
http://sourceforge.net/projects/mysql-python
Jon Stephens
MySQL Documentation Team @ Oracle
MySQL Dev Zone
MySQL Server Documentation
Oracle