A pattern I've written a number of times is roughly:

lines = open(fname)
header = next(lines)
for line in lines:
    process (line, header)

That's not so artificial, I think. Of course, first() would also work here.
But I'm not sure it's any particular advantage in this case.

On Sun, Dec 15, 2019, 12:47 AM Andrew Barnert via Python-ideas <
python-ideas@python.org> wrote:

> On Dec 14, 2019, at 12:36, Christopher Barker <python...@gmail.com> wrote:
> >
> > Of the top of my head, I can’t think of a single non-contrived example
> of using a bare iterator in case that is not specifically doing something
> “special”.
>
> Calling iter on a container is hardly the only way to get an Iterator. You
> also get Iterators from open, map, filter, zip, genexprs, generator
> functions, most itertools functions, etc. And I’m pretty sure at least the
> first of those is learned pretty early and used pretty often by novices.
>
> In fact, I think files are one of the most common ways people learn about
> iterators. There are certainly a lot of StackOverflow dups asking why `for
> line in file:` gives them no lines when just 10 lines earlier the same file
> had 20 lines.
>
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/BP2VRKZQMHRUTK765NYY3BQGN2LBWJTV/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/YJYWUQBEVVB6GTRIUGYSH7UHTNMP3C25/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to