[Python-ideas] Add peekline(), peeklines(n) and optional maxlines argument to readlines()

Antoine Pitrou solipsis at pitrou.net
Fri Sep 30 18:00:19 CEST 2011


On Fri, 30 Sep 2011 07:28:19 -0400
Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Fri, Sep 30, 2011 at 5:42 AM, Giampaolo Rodolà <g.rodola-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> > ...or 2 in case you're not at the beginning of the file.
> > before = f.tell()
> > f.peeklines(10)
> > f.seek(before)
> 
> A context manager to handle the tell()/seek() may be an interesting
> and more general purpose idea:

But it still only works on seekable streams.

Some time ago I proposed a general prefetch() method that would allow
easy protocol-specific buffering on top of non-seekable streams, but
there didn't seem to be a lot of enthusiasm at the time:
http://mail.python.org/pipermail/python-ideas/2010-September/008179.html

Regards

Antoine.





More information about the Python-ideas mailing list