yield_all needed in Python

Francis Girard francis.girard at free.fr
Tue Mar 1 22:53:02 CET 2005


Hi,

No, this won't do. What is needed is a way to yield the results of a generator 
from inside another generator with having to do a for-yield-loop inside the 
outter generator.

Regards,

Francis Girard

Le mardi 1 Mars 2005 22:35, Adam Przybyla a écrit :
>         ... mayby that way:
> ython 2.2.3 (#1, Oct 15 2003, 23:33:35)
> [GCC 3.3.1 20030930 (Red Hat Linux 3.3.1-6)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>
> >>> from __future__ import generators
> >>> def x():
>
> ...  for i in range(10): yield i
> ...
>
> >>> x()
>
> <generator object at 0x82414e0>
>
> >>> for k in x(): print k,
>
> ...
> 0 1 2 3 4 5 6 7 8 9
>
> >>> for k in x(): print k,
>
> ...
> 0 1 2 3 4 5 6 7 8 9
>
> >>> for k in x(): print k,
>
> ...
> 0 1 2 3 4 5 6 7 8 9
>
> >>> yield_all=[k for k in x()]
> >>> yield_all
>
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]




More information about the Python-list mailing list