[Python-Dev] Yield-From Implementation Updated for Python 3

P.J. Eby pje at telecommunity.com
Sun Aug 1 20:16:23 CEST 2010


At 08:49 AM 8/1/2010 -0400, Kevin Jacobs <jacobs at bioinformed.com> wrote:
>On Sun, Aug 1, 2010 at 3:54 AM, Greg Ewing 
><<mailto:greg.ewing at canterbury.ac.nz>greg.ewing at canterbury.ac.nz> wrote:
>I have updated my prototype yield-from implementation
>to work with Python 3.1.2.
>
>
>My work is primarily on the management and analysis of huge genomics 
>datasets.  I use Python generators extensively and intensively to 
>perform efficient computations and transformations on these datasets 
>that avoid the need to materialize them in main memory to the extent 
>possible.   I've spent a great deal of effort working around the 
>lack of an efficient "yield from" construct and would be very 
>excited to see this feature added.

Just so you know, you don't need to wait for this to be added to 
Python in order to have such a construct; it just won't have the 
extra syntax sugar.  See the sample code I posted here using a 
"@From.container" decorator, and a "yield From()" call:

   http://mail.python.org/pipermail/python-dev/2010-July/102320.html

This code effectively reduces your generator nesting depth to a 
constant, no matter how deeply you nest sub-generator 
invocations.  It's not as efficient as the equivalent C 
implementation, but if you're actually being affected by nesting 
overhead now, it will nonetheless provide you with some immediate 
relief, if you backport it to 2.x code.  (It's not very 3.x-ish as it 
sits, really.)



More information about the Python-Dev mailing list