how do I "peek" into the next line?

les_ander at yahoo.com les_ander at yahoo.com
Mon Dec 13 14:09:47 EST 2004


Hi,
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().

Is there a way to do this?
for example:
while 1:
line=stdin.peek_nextline()
if not line: break
if line[0]=="|":
break:
else:
    x=stdin.nextline()
    # do something with x

thanks




More information about the Python-list mailing list