seek in a file

Jeff Shannon jeff at ccvcorp.com
Tue Mar 26 18:32:45 EST 2002


Andreas Penzel wrote:

> Hello NG!
>
> How to jump to a specified line in a file which is read-opened?
> With seek() I can jump to an exact position of  the complete file in
> "byte-steps".
> Is seek able to jump to a line-number?
> If not, what else can I do?

seek() won't work well on text-mode files, because the number of bytes
does not necessarily equal the number of characters (due, mostly to /r/n
<-> /n conversions).  I think that the best you can do to jump to a
particular line number would be using readlines()/xreadlines() and
skipping over the initial (undesired) part.

Jeff Shannon
Technician/Programmer
Credit International





More information about the Python-list mailing list