YIELD_VALUE Byte Code

greg greg at cosc.canterbury.ac.nz
Wed Nov 18 00:17:25 EST 2009


Andreas Löscher wrote:
> Since Python Version 2.5 it behaves the following:
> 	1. pop yield value from stack and return it to
> 		a former gen_send_ex() call from Objects/genobject.c
> 
> 	2. push the yield value on the stack in gen_send_ex() and return

Are you sure about that? I would expect the value pushed to
be the one sent back into the generator using a send() call
if any, or None if the generator is resumed using next()
rather than send().

> 	3. when the generator is executed again, the yield value is
> 		'poped' from the stack again with the POP_TOP opcode

This will happen if the result of the yield expression is
not used for anything in the Python code.

-- 
Greg



More information about the Python-list mailing list