[Tutor] py-postgressql v1.0.1 question

Bill Allen wallenpb at gmail.com
Sun Sep 12 23:11:30 CEST 2010


>
>> Second question is more of a performance question:
>>
>> I don't suspect a "large" # of items in the to_do list, so I *think*
>> that it would be better to just have one SQL statement and then loop
>> through the results 10 times to get the first few records rather than
>> having a seperate sql statement as I have shown here.  I'm too new at
>> python to have a feel for the *right* way to go about this part
>>
>> Could someone point me in the right direction please?
>>
>
As to your second question, I had the same question a few days ago that the
folks here helped me out with.  if you have a list of items you can limit
the loop to get just the first ten items like this:

for x in list_of_results[:10]
     do something with x...

If your object does not easily lend itself to applying a slice, then look
into the itertools module and the islice() method which can help you get and
iterable list from a normaly non-iterable source, like this:

import itertools
for x in itertools.islice(results, 0, 10)
    do something with x...


-Bill
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100912/4888f021/attachment.html>


More information about the Tutor mailing list