"for line in fd" twice
Steven Taschuk
staschuk at telusplanet.net
Tue Jun 3 12:22:34 EDT 2003
Quoth Jack Diederich:
[...]
> The part
> for (line) in fd:
>
> will make a temporary list of all the lines in fd before it starts iterating.
> so by the time you get to the second for() loop the file has been exhausted.
?!
>>> fd = file('python-list')
>>> for line in fd:
... break
...
>>> fd.readline() # fd not exhausted
'=09=09=09 6\n'
It reads ahead, certainly, but it doesn't read the whole file.
--
Steven Taschuk o- @
staschuk at telusplanet.net 7O )
" (
More information about the Python-list
mailing list