[Tutor] Question about nested FOR looping
Wed Apr 30 12:24:07 2003
Bob Gailer wrote in response to Stuart's:
>>Why are they different ?
>Repeating "for s in subitems:" reuses the list each time
>The first call to "for s in sF.readlines():" reads to end of file.
>Subsequent calls do NOT move to start of file; just return ''.
if you do "sF.seek(0)" before "for s in sF.readlines():", i.e.
reset the current file position to the beginning, it will work
as you expect.
BTW, with a modern python you can simply write "for s in sF:".
Calling .readlines() is implied in that context.
Magnus Lycka (It's really Lyckå), firstname.lastname@example.org
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program