how do I "peek" into the next line?

Peter Hansen peter at engcorp.com
Mon Dec 13 22:08:21 EST 2004


les_ander at yahoo.com wrote:
> suppose I am reading lines from a file or stdin.
> I want to just "peek" in to the next line, and if it starts
> with a special character I want to break out of a for loop,
> other wise I want to do readline().
[snip example]

Neither your description above nor your example actually
requires looking ahead.  Are you sure you need to?

You would only need it if *after* breaking out of the
loop, you wanted to continue reading from the file
*and* wanted the line which triggered the loop termination
still to be available for reading.

-Peter



More information about the Python-list mailing list