About mysql cursor and iterator
The MySQLdb
cursor class implements the iterator protocol, so you can simply do this:
cursor.execute(sql)for row in cursor: print row ...
Relevant code from MySQLdb.cursors.BaseCursor:
def __iter__(self): return iter(self.fetchone, None)