how do I "peek" into the next line?
Craig Ringer
craig at postnewspapers.com.au
Mon Dec 13 15:38:46 EST 2004
More information about the Python-list mailing list
Mon Dec 13 15:38:46 EST 2004
- Previous message (by thread): how do I "peek" into the next line?
- Next message (by thread): how do I "peek" into the next line?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, 2004-12-14 at 03:09, les_ander at yahoo.com 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
- Previous message (by thread): how do I "peek" into the next line?
- Next message (by thread): how do I "peek" into the next line?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list