Showing posts with label Why. Show all posts
Showing posts with label Why. Show all posts

Python coroutines

Picture of a quad-helix drone

How to make coroutines return values.

WHY


Maybe you need to handle a large volume of records and you heard coroutines are a good way of doing it. Or maybe you just started looking into them. Whatever the reason, you probably have noticed that a lot of blog posts and tutorials out there show how to code one to print some values.

If you then tried to actually do something with them, you may have ended up here trying to figure out how to coerce the little buggers into returning those values!

You are not alone 😉 I too found it confusing to figure out at first. So I'm going to show you the basics of how to use python coroutines that return values.

If you're in a hurry, let me give you the secret sauce up front: define your yield-expression with a variable! That's all, simple but often overlooked.

For a complete explanation, examples, and walls of text please read on 🙂

Kickoff

I spend considerable amounts of time reading documentation and googling the intertubes in pursuit of learning "that one new thing I need for this".

Frequently, I see people say things like "you can build Amazing Thingamabob (tm)", and "use the combobulator to defenestrate 10x faster!", but they gloss over details which are obvious to someone that already knows the topic, yet impenetrable to first time newbies. That's lead me many a time to ask

OK,but how?


So I decided to share here (every once in a while at least!) what I learned in my deep dives, in hopes that it will save someone a bit of time when looking into those topics 😊

Stay tuned!

Python coroutines

How to make coroutines return values. WHY Maybe you need to handle a large volume of records and you heard coroutines are a good way...