[Python-ideas] Control Flow - Never Executed Loop Body

Vito De Tullio vito.detullio at gmail.com
Tue Mar 22 16:36:23 EDT 2016


Steven D'Aprano wrote:

> def test():
>     x = sentinel = object()
>     iterable = some_function()
>     for x in iterable:
>         # you know the rest

onestly, I just don't like the sentinel approach... while not perfect I 
prefer the explicit check on the throws of the StopIteration of the next 
function


    iterable = iter(some_function())
    try:
        e = iter(iterable)
    except StopIteration:
        # empty
    else:
        # stuff with e
        for e in iterable:
            # stuff with e


-- 
By ZeD



More information about the Python-ideas mailing list