Using xreadlines

Nick Craig-Wood nick at
Sat Feb 28 11:30:04 CET 2009

bearophileHUGS at <bearophileHUGS at> wrote:
>  Brett Hedges:
> > My question is how do I go to a previous line in the file? xreadlines has a statement that gives the next line, and I need a statement that gives me the previous line.<
>  In modern versions of Python you usually don't need xreadlines,
>  because files are iterable.
>  If your files are small, you can just read all the lines in a list
>  with open(...).readlines(), and then just use the item of the list
>  with the n-1 index.

There is also the linecache module

Which may be useful...

Nick Craig-Wood <nick at> --

More information about the Python-list mailing list