[Python-ideas] iterable.__unpack__ method

Jan Kaliszewski zuo at chopin.edu.pl
Sun Feb 24 21:14:28 CET 2013


24.02.2013 17:42, Oscar Benjamin wrote:

> Calls to next() need to be wrapped in try/except StopIteration (it's 
> a
> bad idea to leak these exceptions). So then it becomes:
>
>   try:
>        command = next(iterator)
>   except StopIteration:
>       raise ValueError('need more than 0 values to unpack')

Not necessarily. You can use:

     command = next(iterator, None)

Cheers.
*j



More information about the Python-ideas mailing list