[Python-ideas] Assignments in list/generator expressions
Guido van Rossum
guido at python.org
Sun Apr 10 19:42:57 CEST 2011
On Sun, Apr 10, 2011 at 6:31 AM, Eugene Toder <eltoder at gmail.com> wrote:
>> It isn't strangely missing at all, it's just hard:
>> http://www.python.org/dev/peps/pep-3150/
>
> Local definition in list comprehension is significantly simpler that
> 'given'. Semantically, 'with name = expr' can be treated as a more
> readable form of 'for name in [expr]'. Implementation can use a simple
> assignment.
Eww. Since we already have "with expr as name" I don't think we should
add "with name = expr", even if it's in a different context.
OTOH I am personally a big fan of PEP 3150; now that the moratorium is
lifted I hope that someone will attempt a proper implementation of it
so we can find out all the odd corner cases (which I'm sure will be
plentiful given that this is quite a novel thing for Python).
BTW also +1 on Laura's mini-rant on readability. A lot of folks have
ideas that would add a minor shortcut to the language, without making
a big difference in true expressivity, but with a big potential cost
in readability. (Remember Perl, the ultimate write-only language.) In
defense of 'given' I think that it adds something truly new (variables
that go out of scope before the function containing them returns) in a
very readable way. And the "definition follows use" thing has worked
out pretty well in list comprehensions and generator expressions, if
you ask me.
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list