Need to unread or push back bytes to a file

Noah Spurrier (a) noahnoah.org
Fri Feb 23 20:09:48 EST 2001


I need to push bytes back into a file object. 
Is there a buffered file wrapper for file objects?
(Yes, I looked, but I gave up after almost five minutes of searching.)

I'm reading from a pipe, but this could be the same for a file.
I call an "expect" method which reads until a pattern is found,
but read() with a pipe will read as much data as there is available
in the pipe. When I have found a pattern match I want to return 
the stream with the extra character pushed-back.

Another way to word this is that I want to the of a pattern, but
not past the pattern.

My only other option would be to read(1) character at a time
and then search for the pattern. This will work, but I think a
push-back would be more elegant and efficient.

Yours,
Noah

==================================
Posted via http://nodevice.com
Linux Programmer's Site



More information about the Python-list mailing list