[Python-ideas] Assignments in list/generator expressions
Eric Snow
ericsnowcurrently at gmail.com
Tue Apr 12 09:11:57 CEST 2011
On Tue, Apr 12, 2011 at 12:51 AM, Eric Snow <ericsnowcurrently at gmail.com>wrote:
>
> Like Georg just said, the given clause seems hard to read. He was
> referring to the embedded clause in the list comprehension. I kind of feel
> the same way about the PEP 3150 syntax. I remember when I was first exposed
> to list comprehensions. At first it was hard because it was organized
> differently from any other Python code. However, I have adjusted. Maybe a
> given clause would be the same. I'm just not sure.
>
> That "given" after the expression keeps throwing me off. It just looks out
> of place. Would something like the following be feasible:
>
> c = sqrt(a*a + b*b) given:
> a = retrieve_a()
> b = retrieve_b()
>
> becomes:
>
> given:
> a = retrieve_a()
> b = retrieve_b()
> c = sqrt(a*a + b*b)
>
> where the given statement is effectively _decorating_ the simple statement?
> Unfortunately I am not familiar enough yet with the compiler to know what
> such decoration would entail, much less if it would be entirely too
> complicated. However, I wanted to throw out there an alternative that is
> maybe more readable. It's also one I would probably find more usable for
> plugging in given blocks or disabling them, much like with decorators.
>
> I know this throws off the approach the PEP takes, but I am trying to wrap
> my head around how I would use statement local namespaces. I like how it
> cleans up from the namespace those bits that only matter to the target
> statement. It does make it easier to follow to whom those statements in the
> given block belong. Anyway, this has certainly been an enlightening
> discussion. I hope it bears fruit.
>
> -eric
>
Of course, a decorating syntax does not help with the original scenario,
with embedded given statements in list comprehensions. But maybe that
embedded syntax is too hard to read.
-eric
_______________________________________________
>> Python-ideas mailing list
>> Python-ideas at python.org
>> http://mail.python.org/mailman/listinfo/python-ideas
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110412/12bc506e/attachment.html>
More information about the Python-ideas
mailing list