Seeing next character in an file
Bengt Richter
bokr at oz.net
Mon Jul 28 12:59:01 EDT 2003
On Mon, 28 Jul 2003 12:54:57 +0100, Richie Hindle <richie at entrian.com> wrote:
>
>[Keith]
>> def peek(self, cnt):
>> data = self.read(cnt)
>> self.seek(cnt * -1, 1)
>> return data
>>
>> def peekline(self):
>> pos = self.tell()
>> data = self.readline()
>> self.seek(pos, 0)
>> return data
>
>[Bengt]
>> if you're going to seek/tell, best to do it in binary, and deal with the platform dependent EOLs.
>
>seek() works perfectly with text-mode files as long as you only seek to
>places given to you by tell(). So if Keith's peek() function had used
>tell() and then seek()ed (sought()? 8-) back to that point like his
>peekline() does, there would be no problem.
>
Can you cite a C or C++ standard section that guarantees that seek/tell
will work that way in text mode? (I'm not saying there isn't one, but
I couldn't find one quickly ;-)
Regards,
Bengt Richter
More information about the Python-list
mailing list