*args / **kwargs remodelled

This commit is contained in:
David Halter
2012-05-07 22:41:41 +02:00
parent 40e59c0476
commit 57128bf17f
6 changed files with 131 additions and 72 deletions

View File

@@ -3,5 +3,14 @@
try:
next = next
except NameError:
def next(obj):
return obj.next()
_raiseStopIteration = object()
def next(iterator, default=_raiseStopIteration):
if not hasattr(iterator, 'next'):
raise TypeError("not an iterator")
try:
return iterator.next()
except StopIteration:
if default is _raiseStopIteration:
raise
else:
return default