yield_all needed in Python

Adam Przybyla adam at gliwice.pl
Tue Mar 1 16:35:54 EST 2005


Douglas Alan <nessus at mit.edu> wrote:
> While writing a generator, I was just thinking how Python needs a
> "yield_all" statement.  With the help of Google, I found a
> pre-existing discussion on this from a while back in the Lightweight
> Languages mailing list.  I'll repost it here in order to improve the
> chances of this enhancement actually happening someday.  The original
> poster from the LL mailing list seems mostly concerned with
> algorithmic efficiency, while I'm concerned more about making my
> programs shorter and easier to read.  The ensuing discussion on the LL
> list talks about how yield_all would be somewhat difficult to
> implement if you want to get the efficiency gain desired, but I don't
> think it would be very difficult to implement if that goal weren't
> required, and the goal were limited to just the expressive elegance:
> 
>     A Problem with Python's 'yield'
	... 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]
>>>
Regards
								Adam Przybyla



More information about the Python-list mailing list