On Tue, 2004-12-14 at 03:09, [EMAIL PROTECTED] wrote:
> 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().

Assuming there's a good reason, such as monster lines, not to just read
the next line anyway, I'd suggest read()ing the next character then
seek()ing back by one character to restore the file position.

def peekChar(fileobj):
   ch = fileobj.read(1)
   fileobj.seek(-1,1)
   return ch

--
Craig Ringer

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to