Skip to content
Advertisement

Tag: yield

How do I include part of my code into ‘yield’?

Thank you for your time! Each products, sometimes have more than one model. I got the model ‘name’ and ‘price’ of the respective models within a single product via a for loop. But, how do I ‘transfer’ these details to the ‘yield’ section along with other variables of that same product? Below is my attempt, but i am not getting

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 must be regenerated. So you need

Advertisement