[issue20663] Introduce exception argument to iter

2017-06-18 Thread Terry J. Reedy
Changes by Terry J. Reedy : -- resolution: -> rejected stage: needs patch -> resolved status: open -> closed ___ Python tracker ___

[issue20663] Introduce exception argument to iter

2016-04-26 Thread Raymond Hettinger
Raymond Hettinger added the comment: I really don't think this is worth it. In my programming career, I may have had an occasion to use this only once every few years. -- assignee: rhettinger -> versions: +Python 3.6 -Python 3.5 ___ Python tracker

[issue20663] Introduce exception argument to iter

2014-07-15 Thread Raymond Hettinger
Raymond Hettinger added the comment: The recipe has been in the docs for a good while and as far as I can tell, no one ever uses this in real-code. That suggests that it should remain as a recipe and not become part of the core language (feature creep is not good for learnability or

[issue20663] Introduce exception argument to iter

2014-07-15 Thread Josh Rosenberg
Josh Rosenberg added the comment: The main example that comes to mind was a variant of functools.lru_cache I wrote that expired cache entries after they reached a staleness threshold. The details elude me (this was a work project from a year ago), but it was basically what I was describing; a

[issue20663] Introduce exception argument to iter

2014-07-15 Thread Terry J. Reedy
Terry J. Reedy added the comment: Ram, your opening post here is essentially a copy of your opening post on python-ideas, as if the long discussion there, involving about 6 serious discussants other than you, never happened. Instead of restarting the discussion from scratch, you need to

[issue20663] Introduce exception argument to iter

2014-07-15 Thread Ram Rachum
Ram Rachum added the comment: Terry: Thanks for your example use case. I hope that Raymond would be convinced. I take your point regarding summarizing the discussion, sorry about that. Regarding me writing a test: I'm only willing to write code for a feature for Python if there's general

[issue20663] Introduce exception argument to iter

2014-07-15 Thread Terry J. Reedy
Terry J. Reedy added the comment: Here is a test that now fails. from collections import deque d = deque((0,)) old = [] try: while True: n = d.popleft() old.append((n, len(d))) if n 5: d.extend((n+1, n+2)) except IndexError: pass d =

[issue20663] Introduce exception argument to iter

2014-07-03 Thread Ram Rachum
Ram Rachum added the comment: Hey-ho... Anyone feels like implementing this? (I don't program in C so I can't.) -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20663 ___

[issue20663] Introduce exception argument to iter

2014-07-03 Thread Raymond Hettinger
Raymond Hettinger added the comment: Your suggestion and an example appears to have been taken directly from the itertools recipes: def iter_except(func, exception, first=None): Call a function repeatedly until an exception is raised. Converts a call-until-exception interface to an

[issue20663] Introduce exception argument to iter

2014-07-03 Thread Ram Rachum
Ram Rachum added the comment: I understand. Personally I think it'll be useful enough (and more useful to me than the builtin `sentinel`), but maybe that's just me. And I guess Terry liked it too. I don't know whether other people would like it as well. --

[issue20663] Introduce exception argument to iter

2014-07-03 Thread Josh Rosenberg
Josh Rosenberg added the comment: +1; I've had several cases where I'd have used something like this (for the exact purpose mentioned, to destructively consume an input iterable). I don't think it's more or less useful than the sentinel version, which is convenient for iterating a file by

[issue20663] Introduce exception argument to iter

2014-02-17 Thread Ram Rachum
New submission from Ram Rachum: See discussion: https://groups.google.com/forum/#!searchin/python-ideas/iter/python-ideas/UCaNfAHkBlQ/5vX7JbpCxDkJ `iter` has a very cool `sentinel` argument. I suggest an additional argument `exception`; when it's supplied, instead of waiting for a sentinel