Loading topic
try/except works, and what a special (dunder) method is.2 min readiter() and next() exist. It shows how a for loop uses them.2 min readtry/except. It also assumes you have seen that an iterator is an object with __iter__ and __next__. Here you write one yourself and learn where hand-written iterators usually go wrong.2 min read__iter__, __next__, StopIteration). Here you will see how a generator function gives you the same result as a hand-written iterator class with much less code.2 min readtry/except, and know that iter() and next() drive an iterator. It also assumes you have seen a generator function that uses yield. Here you will learn exactly what happens at each step of a generator's life.2 min readyield, and understand that next() raises StopIteration when an iterator is finished.2 min readfor loops use __iter__ and __next__. Here we look at what "lazy" means in practice and how to measure the memory it saves.2 min readyield and know that a generator is a single-use iterator. A pipeline connects several generators so that each one reads from the one before it. Data moves through the stages one item at a time.2 min read__iter__, __next__, StopIteration), can write generator functions, and can use generator expressions. It covers the most common bug with them: using an iterator after it has been used up.2 min readyield or next() still feels unfamiliar, review the earlier chapters first.2 min read__iter__, __next__, StopIteration) and how a for loop uses it. You should also be comfortable with lambda and with reading from file objects.3 min readyield and know that a generator raises StopIteration when it finishes. It covers yield from, which lets one generator hand work to another.2 min readyield, know what StopIteration is, and have seen yield from at a basic level. It covers how a generator hands back a final value, where that value goes, and the mistakes that follow from it.2 min readyield and resumes on next(). It also assumes you are comfortable with try/except/finally. So far data has flowed one way, from the generator to the caller. Generators can also receive values and exceptions while they are suspended.2 min read