This is an excellent summary of Python generators. I'm fairly new to Python and have seen and read a bit about generators, but this is the first time anyone has described bi-directional communication using send(). This makes them far more powerful than I realised. Thank you for such an informative explanation.
@kingsgambit3 жыл бұрын
These videos are some of the best Python tutorials on KZbin. What makes them so good is how precise, short, compact, yet detailled you explain the matter and support it with well chosen examples. Perfect!
@pepijn12875 жыл бұрын
The clearest explanation I've seen! Thanks!
@tymofiidmytrenko34184 жыл бұрын
Awesome explanation of .send method of generators. I tried to grasp the concept for a while, but with no luck... this video just rocks and I love the game based demo as well! I have now subscribed to your channel.
@Zakaramut6 жыл бұрын
great teaching man, love your work!
@jonahnio56425 жыл бұрын
Hi Sebastian thanks so much for the video which will help me apply the asynchronous concept to my work. I also watched your video on asyncio and not sure what to use .what is the advantage of using asyncio over generators thanks a lot
5 жыл бұрын
Think of asyncio as a framework that is based on generator functions, which are often called coroutines in this context. Whether you need all the superpowers of asyncio, or whether regular generators are sufficient depends on what you want to do!
@johnnybravo23424 жыл бұрын
To anyone watching: In some version of python behavior of generators changed and with code presented in a video it returns with both StopIteration and RuntimeError exception. According to github.com/allenai/bilm-tf/issues/170#issuecomment-469713724 you have to change 'raise StopIteration' to simply 'return' and the exception will be handled as it should. Hope i helped :)
@maicoldlb5 жыл бұрын
Thanks a lot for this !!
@caseyalanjones4 жыл бұрын
This helped me a lot, but what I still don't get is the return value of the yield statement for the first iteration... If you send None to icat for the first iteration, then wouldn't mouse then be None in "mouse = yield cat"? I suppose not, since you otherwise wouldn't have been able to access col and row attributes on a NoneType object... but I don't get how this works. How is mouse an Animal on the first iteration, even though you send None? That's the only part I'm still confused about. Otherwise fantastic explanation and demo! Thanks a lot.
@caseyalanjones4 жыл бұрын
Never mind, I think I figured it out. In your example a value is yielded, execution of the generator is paused, then a value is sent in - so the None value is already overwritten as soon as execution returns to the generator and before Animal attributes are accessed.
@billybabcokcs82245 жыл бұрын
great work
@nairazak_art2 жыл бұрын
Thank you, I was reading Effective Python and I wasn't able to understand bidirectional communication
@RafaganAbreu4 жыл бұрын
Very nice tutorial!
@gilbertodelavega3593 жыл бұрын
I don't understand why you assigned the value of the yielded value to the mouse in the line "mouse = yield cat"? Wouldn't that overwrite the value of mouse that was passed in and make mouse and cat have the same value? I don't understand that line of code at all...
@JoaoVitorBRgomes3 жыл бұрын
No. mouse = yield cat is not the same as mouse = cat.
@caseyalanjones4 жыл бұрын
WorkRave cameo 😂
@JeaneAdix6 жыл бұрын
are you norwegian?
6 жыл бұрын
Close, I'm Dutch!
@MrDmitriM5 жыл бұрын
+++
@Kornelux955 жыл бұрын
4:25 StopIteration exception is not a python's way to tell us generator functions is exhausted. StopIteration exception is a python's way to tell that Iterator's stream of data has ended (when there is no more data to return/yield). Generator functions returns object called Generator Iterator. So to be more precise when we get StopIteration in 4:25 it means that the Generator Iterator's stream of data is exhausted.