[Python-ideas] PEP 479 and take()

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Dec 10 22:42:44 CET 2014


> On Wed, Dec 10, 2014 at 4:05 AM, Oscar Benjamin 
> <oscar.j.benjamin at gmail.com <mailto:oscar.j.benjamin at gmail.com>> wrote:
 >
>     class TakeError(Exception):
>         pass
> 
>     def take(iterator, n=None):
>         if n is None:
>             try:
>                 return next(iterator)
>             except StopIteration:
>                 raise TakeError
>         else:
>             return tuple(take(iterator) for _ in range(n))

Won't that just shift the problem from leaked StopIterations
to leaked TakeErrors?

-- 
Greg


More information about the Python-ideas mailing list