Is there a better/simpler way to filter blank lines?
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Wed Nov 5 04:56:48 EST 2008
On Wed, 05 Nov 2008 14:39:36 +1100, Ben Finney wrote:
> Marc 'BlackJack' Rintsch <bj_666 at gmx.net> writes:
>
>> On Wed, 05 Nov 2008 13:18:27 +1100, Ben Finney wrote:
>>
>> > Marc 'BlackJack' Rintsch <bj_666 at gmx.net> writes:
>> >
>> > Your example shows only that they're important for grouping the
>> > expression from surrounding syntax. As I said.
>> >
>> > They are *not* important for making the expresison be a generator
>> > expression in the first place. Parentheses are irrelevant for the
>> > generator expression syntax.
>>
>> Okay, technically correct but parenthesis belong to generator
>> expressions because they have to be there to separate them from
>> surrounding syntax with the exception when there are already enclosing
>> parentheses. So parenthesis are tied to generator expression syntax.
>
> No, I think that's factually wrong *and* confusing.
>
> >>> list(i + 7 for i in range(10))
> [7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
>
> Does this demonstrate that parentheses are “tied to” integer literal
> syntax? No.
You can use integer literals without parenthesis, like the 7 above, but
you can't use generator expressions without them. They are always
there. In that way parenthesis are tied to generator expressions.
If I see the pattern ``f(x) for x in obj if c(x)`` I look if it is
enclosed in parenthesis or brackets to decide if it is a list
comprehension or a generator expression. That may not reflect the formal
grammar, but it is IMHO the easiest and pragmatic way to look at this as
a human programmer.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list