File object + readline + iter

Roman Yakovenko romany at actimize.com
Wed May 21 16:38:39 EDT 2003


	You guessed right. I found out the problem at very early stage
of my program.
Thanks to good python documentation. My question was more filosofic,
than practic. 
I don't understand why I need this work around if I can implement look
ahead algorithm
also at readline method. May be I missed smth ? For answer my own
question I think that 
I need to see build in file object code.

Thanks for response.

Roman


> -----Original Message-----
> From: Andrew Bennetts [mailto:andrew-pythonlist at puzzling.org] 
> Sent: Wednesday, May 21, 2003 3:22 PM
> To: python-list at python.org
> Subject: Re: File object + readline + iter
> 
> 
> 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.
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list