On Sun, Dec 15, 2019 at 6:40 AM David Mertz <me...@gnosis.cx> wrote:

> Yes, of course. I was just trying to illustrate using next() in a
> non-artificial way. In real code (but truthfully, probably not in my quick
> "one off" scripts) I write
>
> lines = get_lines_file_or_elswhere(resource)
> header = next(lines, sentinel)
> if looks_like_header(header):
>     for line in lines:
>         ...
>

Hmm, interesting -- so this means that you do write code expecting a
generic iterator, rather than a file-like object.

I can't say I've ever done that, nor seem anyone else to that.

I'm curious: what other iterators might this code be expected to work with?
(that is, a list of lines, as returned by file.readlines() would not work
--you'd have to wrap it in iter() first...

But apparently it reflects the move that Python has been making toward
being all about iterators.

I think first() would be a help mostly to folks that DON'T think primarily
in terms of iterators.  And frankly, I think that is a population Python
should strive to support.

For the record, I write a lot of code that looks like:

data_file = get_lines_file_(resource)
header = data_file.readline()
if looks_like_header(header):
    for line in data_file:
        ...

That is, I'm always expecting a file-like object, rather than a generic
iterator. That may be because I developed habits long before files were
iterators....

BTW: this has been a REALLY LONG thread -- I think it's time for a concrete
proposal to be written up, sonce it appears we're not all clear on what
we're talking about. For my part I think a first() function would be nice,
an am open to a couple variations, so someone with a stronger opinion
should propose something.

Tim: what version do you have in mind?

-CHB


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
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/5GAFOT6HAXE7AOK3NHHQ6D3IIETPEXOQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to