Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to chain iterator send() for Python 2 #50

Closed
bslatkin opened this issue Dec 22, 2017 · 1 comment
Closed

Document how to chain iterator send() for Python 2 #50

bslatkin opened this issue Dec 22, 2017 · 1 comment
Labels
1ed First Edition enhancement

Comments

@bslatkin
Copy link
Owner

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:

https://gist.github.com/bslatkin/6934d53441198f3db30d32cb7f1dbf73#file-my_coroutine_in_py_27-py-L33

@bslatkin
Copy link
Owner Author

This is going to be out of scope in future releases because it doesn't apply to Python 3.

@bslatkin bslatkin added the 1ed First Edition label Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1ed First Edition enhancement
Projects
None yet
Development

No branches or pull requests

1 participant