Iterate over text file, discarding some lines via context manager

Marko Rauhamaa marko at
Fri Nov 28 18:55:40 CET 2014

Dave Angel <davea at>:

> Why would you prefer that over a generator function, as given earlier
> in the thread? See for example Ned's message. By using 'yield', you
> get Python to generate all the class boilerplate for you.

I think the OP can learn from the comparison. One question, many

 * Here's how you write a generator.

 * Here's how you write a context manager class. You run into those
   quite often as well.

 * See how much more suitable a generator is in this case.

No need to shoot down those who only try to be helpful.


More information about the Python-list mailing list