Style question on recursive generators
aleaxit at yahoo.com
Mon Oct 18 16:27:43 CEST 2004
Carlos Ribeiro <carribeiro at gmail.com> wrote:
> Yes, that's a good point, and it's one of the reasons I tend to prefer
> the generator now. But anyway, it's just me, or does the 'chained
> yield' look ugly to someone else? It may be just a question of getting
> used to it, but nevertheless it's bugging me...
I'm not sure why it should look ugly to you. What alternatives would
you consider non-ugly for the common (in any generator) idiom:
for x in y: yield x
Perhaps some syntax hack such as a new statement keyword 'yieldall'
where the above idiom could be expressed as
? Or some other syntax hack such as 'yield<<y', or 'yield from y',
ditto? Personally, it would seem to me that such special syntax would
be just one more bit of Python to learn, without substantial benefits,
but that's because I see nothing ugly in today's idiom -- it does just
what it says, plainly and unpretentiously...
More information about the Python-list