Pre-PEP: reverse iteration methods

John Roth newsgroups at jhrothjr.com
Wed Sep 24 06:29:15 EDT 2003


"Stephen Horne" <$$$$$$$$$$$$$$$$$@$$$$$$$$$$$$$$$$$$$$.co.uk> wrote in
message news:f4b2nv8vs81v6egonckq7935jmh6a8gku6 at 4ax.com...
> On Wed, 24 Sep 2003 00:30:31 GMT, "Raymond Hettinger"
> <vze4rx4y at verizon.net> wrote:
>
> >Proposal
> >========
> >
>
> >* Should file objects be included?  Implementing reverse iteration may
not
> >  be easy though it would be useful on occasion.
>
> IMO no - doing this essentially needs the whole file to be read into
> memory, in which case you may as well read the whole file into a list
> and then iterate the list backwards.

Actually, it doesn't. It does require that the file be read into the
buffers backwards, but from there it's simply a matter of doing
a reverse scan for the line ending characters. The difficulty is that
the entire algorithm would have to be done in C, without any
significant help from the standard library.

John Roth
>
>
>
> -- 
> Steve Horne
>
> steve at ninereeds dot fsnet dot co dot uk






More information about the Python-list mailing list