File object + readline + iter
Andrew Bennetts
andrew-pythonlist at puzzling.org
Wed May 21 09:21:57 EDT 2003
On Wed, May 21, 2003 at 07:45:46AM +0300, Roman Yakovenko wrote:
> Hi. I have a few questions.
> 1. Is there is some reason why readline + iter cann't be used
> together without correcting file pointer position (seek) ?
You don't give a sample of the code that doesn't work the way you expect, so
I can only guess what your exact problem is. I seem to recall that
iter(file) doesn't well with file.readline due to the way iter file buffers,
but it's easy to work around:
lines = iter(file_obj)
for line in lines:
if shouldSkipNextLine(line):
lines.next()
(I'm guessing your code looked something like:
for line in file_obj:
if shouldSkipNextLine(line):
file_obj.readline()
)
If this doesn't answer your question, be more specific about what your
problem is.
-Andrew.
More information about the Python-list
mailing list