Since there's no yield from you need to use a loop in order to chain iterators. However, in the default explained by item 40, a simple loop doesn't properly pass through sending. You have to nest the send() calls like this:
it = count_neighbors(y, x)
try:
value = next(it)
while True:
value = it.send((yield value))
except MyReturn as e:
neighbors = e.value
A full example showing the problem is worked out in this gist:
Since there's no
yield from
you need to use a loop in order to chain iterators. However, in the default explained by item 40, a simple loop doesn't properly pass through sending. You have to nest thesend()
calls like this:A full example showing the problem is worked out in this gist:
https://gist.github.com/bslatkin/6934d53441198f3db30d32cb7f1dbf73#file-my_coroutine_in_py_27-py-L33