I am parsing a 2 GB log file from a data logger. My function built a list of parsed records and returned it, and the script ran out of memory. A colleague changed records.append(rec) to yield rec and removed the return, and now it runs in a few megabytes.
I do not understand what changed. When I call the function and print the result I get <generator object ...> instead of data, and a second for loop over the same result produces nothing. What does yield actually do, and when should I use it?




