[Python-ideas] iterable.__unpack__ method
MRAB
python at mrabarnett.plus.com
Sun Feb 24 21:34:47 CET 2013
On 2013-02-24 20:14, Jan Kaliszewski wrote:
> 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)
>
That's not the same thing.
Normally when unpacking, it raises ValueError if there are too few
items. That's what we want to preserve.
More information about the Python-ideas
mailing list