[Python-Dev] code blocks using 'for' loops and generators

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Mar 13 07:51:43 CET 2005

Brian Sabbey wrote:
> I prefer re-using the 'for' loop for this purpose because it allows the 
> problem to be solved in a general way by re-using a structure with which 
> most users are already familiar, and uses generators, which are easier 
> to use in this case than defining a class with __exit__, __enter__, etc.

But this is an abuse of both the for-loop and the generator.
It's using a for-loop for something that does not loop and
is never intended to loop, and it's using yield to do
something other than producing a value for consumption.

I'd rather see a new mechanism altogether for this very
different use case.

> -Brian


More information about the Python-Dev mailing list