Frankenstring

Thomas Lotze thomas at thomas-lotze.de
Tue Jul 12 21:49:16 EDT 2005


Scott David Daniels wrote:

> Now if you want to do it for a file, you could do:
> 
>      for c in thefile.read():
>          ....

The whole point of the exercise is that seeking on a file doesn't
influence iteration over its content. In the loop you suggest, I can
seek() on thefile to my heart's content and will always get its content
iterated over exactly from beginning to end. It had been read before any
of this started, after all. Similarly, thefile.tell() will always tell me
thefile's size or the place I last seek()'ed to instead of the position of
the next char I will get.

-- 
Thomas




More information about the Python-list mailing list