[Python-ideas] Re: Documenting iterators vs. iterables

2020-05-15 Thread Stephen J. Turnbull
Chris Angelico writes: > > (Technical note: for the convenience of implementors of 'for', > > when iter is applied to an iterator, it always returns the > > iterator itself.) > > That's not a mere technical detail - that's actually part of the > definition of an iterator, namely

[Python-ideas] Re: Documenting iterators vs. iterables

2020-05-15 Thread Chris Angelico
On Fri, May 15, 2020 at 7:23 PM Stephen J. Turnbull wrote: > > Chris Angelico writes: > > > > (Technical note: for the convenience of implementors of 'for', > > > when iter is applied to an iterator, it always returns the > > > iterator itself.) > > > > That's not a mere technical

[Python-ideas] Re: Documenting iterators vs. iterables

2020-05-15 Thread Ricky Teachey
On Fri, May 15, 2020 at 5:37 AM Chris Angelico wrote: > On Fri, May 15, 2020 at 7:23 PM Stephen J. Turnbull > wrote: > > > > Chris Angelico writes: > > > > > I don't like this term "converted". > > > > I refuse to die on that hill. :-) Suggest a better term, I'll happily > > use it until somet

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Steven D'Aprano
On Thu, May 14, 2020 at 09:47:36AM -0700, Andrew Barnert wrote: > On May 14, 2020, at 03:01, Steven D'Aprano wrote: > > > > On Mon, May 11, 2020 at 10:41:06AM -0700, Andrew Barnert via Python-ideas > > wrote: > > > >> I think in general people will expect that a slice view on a sequence > >>

[Python-ideas] Re: Adding slice Iterator to Sequences

2020-05-15 Thread Rhodri James
On 14/05/2020 19:56, Andrew Barnert wrote: On May 14, 2020, at 10:45, Rhodri James wrote: On 14/05/2020 17:47, Andrew Barnert via Python-ideas wrote: Which is exactly why Christopher said from the start of this thread, and everyone else has agreed at every step of the way, that we can’t change

[Python-ideas] Re: [Suspected Spam]Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Steven D'Aprano
On Mon, May 11, 2020 at 02:37:15PM +0900, Stephen J. Turnbull wrote: > I think part of the problem is that people rarely see explicit > iterator objects in the wild. Most of the time we encounter iterator > objects only implicitly. Nomenclature *is* a problem (I still don't > know what a "genera

[Python-ideas] Re: [Suspected Spam]Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Steven D'Aprano
On Wed, May 13, 2020 at 10:51:58AM -0700, Andrew Barnert via Python-ideas wrote: > Students often want to know why this doesn’t work: [snip example showing the difference between iterators which become exhausted after iteration, and sequences that don't] > The answer is that files are iterators

[Python-ideas] Re: Documenting iterators vs. iterables [was: Adding slice Iterator ...]

2020-05-15 Thread Steven D'Aprano
On Fri, May 15, 2020 at 12:17:56PM +0900, Stephen J. Turnbull wrote: > Terrible example, since a glass is just a geologically slow liquid. ;-) That's a myth :-) The key test for a liquid is not whether is flows, since solids also flow. (In solids, this usually happens very, very slowly, and is

[Python-ideas] Re: Documenting iterators vs. iterables

2020-05-15 Thread Steven D'Aprano
On Fri, May 15, 2020 at 05:58:16AM -0400, Ricky Teachey wrote: > Perhaps use the iter function name as the generic? "itered". As opposed to > "iterated" or "iterated over". > > Example: > > "the statement below iterates over an iterator, itered from a sequence" Or just avoid the issue: "The st

[Python-ideas] Re: Documenting iterators vs. iterables [was: Adding slice Iterator ...]

2020-05-15 Thread David Mertz
On Thu, May 14, 2020, 11:20 PM Stephen J. Turnbull > > I can teach a child why a glass will break permanently when you hit > > it while a lake won’t by using the words “solid” and “liquid”. > > Terrible example, since a glass is just a geologically slow liquid. ;-) > It isn't though. I used to

[Python-ideas] Re: Documenting iterators vs. iterables [was: Adding slice Iterator ...]

2020-05-15 Thread Greg Ewing
On 16/05/20 12:26 am, Steven D'Aprano wrote: Arguments over the precise definition of states of matter are, to some degree, futile. I've seen amorphous solids described as "liquids that don't flow" and non-Newtonian liquids described as "solids that flow". I think this just shows that nature d

[Python-ideas] Re: Documenting iterators vs. iterables [was: Adding slice Iterator ...]

2020-05-15 Thread Jonathan Fine
Here's an article about recent research: ___ 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://ma

[Python-ideas] Re: Documenting iterators vs. iterables [was: Adding slice Iterator ...]

2020-05-15 Thread Jonathan Fine
Oops, try again; Here's an article about recent research. I found it fascinating. https://www.quantamagazine.org/ideal-glass-would-explain-why-glass-exists-at-all-20200311/ It starts: Glass is anything that’s rigid like a crystal, yet made of disordered molecules like a liquid. To understand why

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Christopher Barker
TL;DR: no need to come to consensus about the most "Pythonic" API for a sequence view -- due to potential name clashes, adding a dunder is pretty much the only option. Details below: On Fri, May 15, 2020 at 3:50 AM Steven D'Aprano wrote: > I think lst.view[10:20] fits that bill. > > Have we fo

[Python-ideas] Re: Documenting iterators vs. iterables

2020-05-15 Thread Christopher Barker
I think maybe some of the trouble here, particularly in teaching is the word "is" (in English, not the Python keyword). As in: "A file object IS and iterator" and "A zip object IS an iterator" I know in OO parlance, "is a" can be used to designate subclassing (or an appropriate use for it) and i

[Python-ideas] Re: Adding slice Iterator to Sequences

2020-05-15 Thread Christopher Barker
A > > different method/property/class/function that gives you iterators > > would be fine. > > We already have such. It's called itertools.islice(). > If you had read the proposal, you’d know that was brought up, obviously. I'm sorry, but you're missing the point here. You and Christopher see

[Python-ideas] Re: Documenting iterators vs. iterables [was: Adding slice Iterator ...]

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 14, 2020, at 20:17, Stephen J. Turnbull wrote: > > Andrew Barnert writes: > >> Students often want to know why this doesn’t work: >> with open("file") as f: >> for line in file: >> do_stuff(line) >> for line in file: >> do_other_stuff(line) > > Sure.

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 03:50, Steven D'Aprano wrote: > > On Thu, May 14, 2020 at 09:47:36AM -0700, Andrew Barnert wrote: >>> On May 14, 2020, at 03:01, Steven D'Aprano wrote: >>> >> Which is exactly why Christopher said from the start of this thread, >> and everyone else has agreed at every step

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 13:03, Christopher Barker wrote: > > Taking all that into account, if we want to add "something" to Sequence > behavior (in this case a sequence_view object), then adding a dunder is > really the only option -- you'd need a really compelling reason to add a > Sequence metho

[Python-ideas] Re: Improve handling of Unicode quotes and hyphens

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 14, 2020, at 20:01, Stephen J. Turnbull wrote: > > Executive summary: > > AFAICT, my guess at what's going on in the C tokenizer was exactly > right. It greedily consumes as many non-operator, non-whitespace > characters as possible, then validates. Well, it like like it’s not quite

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Christopher Barker
On Fri, May 15, 2020 at 5:45 PM Andrew Barnert wrote: > On May 15, 2020, at 13:03, Christopher Barker wrote: > > > > Taking all that into account, if we want to add "something" to Sequence > behavior (in this case a sequence_view object), then adding a dunder is > really the only option -- you'd

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 18:21, Christopher Barker wrote: > >> On Fri, May 15, 2020 at 5:45 PM Andrew Barnert wrote: > >> On May 15, 2020, at 13:03, Christopher Barker wrote: >> > >> > Taking all that into account, if we want to add "something" to Sequence >> > behavior (in this case a sequence_v

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Andrew Barnert via Python-ideas
On May 15, 2020, at 18:21, Christopher Barker wrote: > > Hmm, more thought needed. Speaking of “more thought needed”, I took a first pass over cleaning up my quick&dirty slice view class and adding the slicer class, and found some bikesheddable options. I think in most cases the best answer is

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Steven D'Aprano
On Fri, May 15, 2020 at 01:00:09PM -0700, Christopher Barker wrote: > I know you winked there, but frankly, there isn't a clear most Pythonic API > here. Surely you do'nt think PYhton should have no methods? That's not what I said. Of course Python should have methods -- it's an OOP language aft

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-15 Thread Steven D'Aprano
On Fri, May 15, 2020 at 05:44:59PM -0700, Andrew Barnert wrote: > Once you go with a separate view-creating function (or type), do we even need > the dunder? Possibly not. But the beauty of a protocol is that it can work even if the object doesn't define a `__view__` dunder. - If the object de