
On Thu, Feb 19, 2009 at 7:28 AM, Antoine Pitrou <solipsis@pitrou.net> wrote:
Greg Ewing <greg.ewing@...> writes:
Use of StopIteration to return values -------------------------------------
Why not a dedicated exception (e.g. GeneratorReturn) instead? Two advantages to doing so: * people mistakingly doing a "for" loop over such a generator would be reminded that they are missing something (the return value) * you could take advantage of existing iterator-consuming features (e.g. "yield from map(str, innergenerator())"), since they would just forward the exception instead of silencing it
Seconded -- but I would make it inherit from StopIteration so that the for-loop (unless modified) would just ignore it. -- --Guido van Rossum (home page: http://www.python.org/~guido/)