uchicago-bio / 2016-Autumn-Forum

1 stars 0 forks source link

"Yield" vs. line-by-line parsing #13

Closed jefftempus closed 7 years ago

jefftempus commented 7 years ago

As a Python amateur, I haven't had a lot of experience with the concept of "yield," which was the highlight of the two suggested readings for parsing possibly very large text/fasta files with 1000's of sequences.

Though I have had experience in iterating through files line-by-line, capturing what you need from one line and moving to the next. It has its own share of inefficiencies but seems like another approach.

Is there a major efficiency difference in yield vs. "for line in .... :" ?

tabinks commented 7 years ago

Using yield gives your more control over the flow of your program. You could write a generator function that returns an sequence entry from a file instead of just returning line-by-line. You would read the file and only call yield once you've detected that you have completely collected a sequence.

If you are not comfortable using it, do not worry. It is not a requirement. Although, you may want to revise your code later in the course.