[Tutor] Help with cursors please

Alan Harris-Reid aharrisreid at googlemail.com
Fri Feb 5 04:22:12 CET 2010


Kent Johnson wrote:
> On Thu, Feb 4, 2010 at 12:47 PM, Alan Harris-Reid
> <aharrisreid at googlemail.com> wrote:
>   
>> Hi,
>>
>> I have a SQLite cursor which I want to traverse more than once, eg...
>> for row in MyCursor:
>>   method1(row)
>>  then later...
>> for row in MyCursor:
>>   method2(row)
>>  Method2 is never run, I guess because the pointer is at the bottom of the
>> row 'stack' after the first 'for' loop
>>
>> How can I move the pointer back to the top of the stack?  Or do I have to
>> reload the cursor first?
>>     
>
> Either reload the cursor or use fetchall() to get the results into a
> list and iterate the list.
>
> rows = MyCursor.fetchall()
> for row in rows;
>   ...
>
>
> Kent
Thanks for the reply Kent.  I used fetchall() to get the results into a 
list and everything works fine now.

Regards,
Alan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100205/699afa86/attachment.htm>


More information about the Tutor mailing list