Understanding yield in python
I’m testing a script against a live database.
Accessing the db is slow and the test iterates trough all rows each time.
Since I’m gradually increasing rows on each test run, I need only some, but not all
rows.
Problem: How can I avoid loading all rows but only fetch some
?
Solution: Use yield
Takeaway: Memorize the word yield
as alias for fetch some.
Why words matter is beautifully reasoned by Raymond Hettinger in this youtube video.