yield_all needed in Python
Steven Bethard
steven.bethard at gmail.com
Wed Mar 2 14:38:27 EST 2005
Terry Reedy wrote:
> "Steven Bethard" <steven.bethard at gmail.com> wrote in message
> news:aNSdnYFA69ICiLjfRVn-ow at comcast.com...
>>
>>My suspicion is that if he doesn't like the * syntax when there's a close
>>parallel to the argument parsing usage, he's not likely to like it when
>>there isn't one.
>
> Hmm. My impression is that Guido did not like x,*y=iterable because he
> does *not* see it as a 'close parallel' but as a strained analogy. To me,
> yield *iterable is closer to the use in function calling. It would mean
> 'unpack in time' rather than 'unpack in space' but that is natural (to me,
> anyway) since that is what generators are about.
I don't see the * in
yield *iterable
being much closer to the use in argument unpacking. Note what happens
to iterables after *:
py> def gen():
... yield 1
... yield 2
... print "complete!"
...
py> def f(*args):
... print args
...
py> f(*gen())
complete!
(1, 2)
The entire iterable is immediately exhausted. So if
yield *iterable
is supposed to parallel argument unpacking, I would expect that it would
also immediately exhaust the iterable, e.g. it would be equivalent to:
for item in tuple(iterable):
yield item
which I don't think is what the OP wants.
I'm certain I could get used to the syntax. I'm only suggesting that I
don't find it very intuitive. (And I *have* thought a lot about
argument unpacking -- see my older threads about *args being an iterable
instead of a tuple.)
STeVe
More information about the Python-list
mailing list