Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def my_coroutine():
- while True:
- received = yield
- print('Received:', received)
- if received == 'Third':
- return 3
- def second_coroutine():
- a = yield from my_coroutine()
- yield a
- it = my_coroutine()
- next(it)
- it.send('First')
- it.send('Second')
- try:
- v = it.send('Third')
- except StopIteration as e:
- print('StopIteration, returned value:', e.value)
- it2 = second_coroutine()
- next(it2)
- it2.send('First')
- it2.send('Second')
- v2 = it2.send('Third')
- print('value of yield from:', v2)
- >>>
- Received: First
- Received: Second
- Received: Third
- StopIteration, return value: 3
- Received: First
- Received: Second
- Received: Third
- value of yield from: 3
Add Comment
Please, Sign In to add comment