best solution to for loop

Dan dan at
Thu Sep 22 12:25:02 CEST 2005

> Hi, I have several apps which connect to a database,  fetch some data
> an put this into a gtk.TreeStore, but if the result set is 1500 row
> long, the app response slowly

The first thing to test is whether it's Python or the database that's
the bottleneck. 1500 rows isn't all that much for a database, but it
might not be trivial either.

Even if the bottleneck is Python, the solution might be to limit the
amount of data that you process. For example, rather than displaying all
1500 records in a tree (nobody wants to scroll through 1500 records
anyway), try grouping them by the first letter of their name. Display a
tree consisting of each letter, then when the user clicks that letter:

  cur.execute("SELECT * FROM clients WHERE name LIKE '" + letter + "%'")

   I had picked out the theme of the baby's room and done other
   things. I decided to let Jon have this.
       - Jamie Cusack (of the Netherlands), whose husband Jon
         finally talked her into letting him name their son Jon 2.0

More information about the Python-list mailing list