2014-03-23 15:48:29 -04:00
|
|
|
def gen():
|
|
|
|
yield 1
|
|
|
|
return 42
|
|
|
|
|
|
|
|
g = gen()
|
|
|
|
print(next(g))
|
|
|
|
try:
|
|
|
|
print(next(g))
|
|
|
|
except StopIteration as e:
|
2018-08-17 01:46:04 -04:00
|
|
|
print(type(e), e.args)
|
2018-09-27 01:18:24 -04:00
|
|
|
|
|
|
|
# trying next again should raise StopIteration with no arguments
|
|
|
|
try:
|
|
|
|
print(next(g))
|
|
|
|
except StopIteration as e:
|
|
|
|
print(type(e), e.args)
|