Skip to content

Tag: yield

Misunderstood python yield

This code below works correct : But this function raises StopIteration. I don’t understand why ? Answer You have: Notice line = f.readline() This only reads 1 line from the file. Compare: with this: yield can only be called once with a particular object or expression. Once it is used by the receiver it …