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

Sven R. Kunze srkunze at mail.de
Tue Mar 22 17:52:50 EDT 2016


On 22.03.2016 21:36, Vito De Tullio wrote:
> 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

I tend to agree.

Best,
Sven


More information about the Python-ideas mailing list