file.readline() after a seek() breaking up lines
Mark Day
mday at apple.com
Fri Mar 5 16:46:21 EST 2004
In article <ba1b9669.0403051205.5d278f0b at posting.google.com>, fd
<frnakd at aol.com> wrote:
> I am a newcomer to python, and I hope someone can point out to me why
> my calls to file.readline() (after a seek) are returning mangled lines.
> Calling readline twice after each seek, eliminates the problem.
Seek positions to an arbitrary byte offset (at least on most OSes).
Chances are, you're seeking into the middle of a line. The first
readline() returns the remainder of that line (which is what I assume
you mean by a "mangled" line). Subsequent readlines will return whole
lines since the previous readline left the current position just after
the end of the previous line.
-Mark
More information about the Python-list
mailing list