Implement send() method for generators.

This commit is contained in:
Paul Sokolovsky
2014-01-26 20:50:11 +02:00
parent 56bb636014
commit bf38e2a03a
3 changed files with 35 additions and 1 deletions

View File

@@ -0,0 +1,15 @@
def f():
n = 0
while True:
n = yield n + 1
print(n)
g = f()
try:
g.send(1)
except TypeError:
print("caught")
print(g.send(None))
print(g.send(100))
print(g.send(200))