
One more and then I'll let this go. On Mon, Dec 9, 2019 at 10:49 AM Andrew Barnert <abarnert@yahoo.com> wrote:
On Dec 8, 2019, at 21:41, Guido van Rossum <guido@python.org> wrote:
I do have to admit that I'm probably biased because I didn't recall 2-arg next() myself until it was mentioned in this thread.
That’s because you learned Python before 2.6, when there was no 2-arg next (because next was a method).
I know that for me something different was at play, and I suspect it's the same for many others. 1-arg next() is essential in straddling code because .next() was renamed .__next__() in Python 3, so everybody doing any migration work at all quickly learns about it by example. But 2-arg next() is *not* essential and one is much less likely to learn about it from reading other code (except for itertools lovers). Another thing is that 1-arg next() raises StopIteration, and almost every next() caller has to handle that. So again many people see examples of how to do this. (It's telling that we have PEP 479 to "tame" uncaught StopIteration exceptions.) But cases where 2-arg next() can be used instead of try/except are rare. In fact, I found that one case in test_itertools.py by grepping the stdlib for 'except StopIteration'. Almost no code I found that way was amenable to using 2-arg next() -- that one test in test_itertools.py was literally the first example I found that was, after inspecting dozens of occurrences. So while 1-arg next() and the try/except StopIteration pattern are essential and well-known, 2-arg next() is relatively esoteric and consequently (I think) not nearly as well-known. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>