next() Python 2.6.
. .next() Python 2:
try:
ByteIter.next() << 8
except StopIteration:
pass
.next() StopIteration, , StopIteration.
:
_sentinel = object()
def next(iterable, default=_sentinel):
try:
return iterable.next()
except StopIteration:
if default is _sentinel:
raise
return default
This works the same as Python 2.6:
>>> next(iter([]), 'stopped')
'stopped'
>>> next(iter([]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in next
StopIteration
source
share