[Python-Dev] comprehension abbreviation
"Martin v. Löwis"
martin at v.loewis.de
Tue Mar 15 23:14:24 CET 2005
Eric Nieuwland wrote:
>> [ <test> for <exprlist> in <testlist> <list-iter-opt> ]
> Aren't these names a bit mixed up w.r.t. what's in that position?
It comes more-or-less straight out of Grammar/Grammar, so: no,
I don't think so.
> As far as I know
> <test> is not a test but a function as it produces any value not just
> True/False
To quote more of Grammar/Grammar, it is
test: and_test ('or' and_test)* | lambdef
and_test: not_test ('and' not_test)*
not_test: 'not' not_test | comparison
comparison: expr (comp_op expr)*
comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not'
expr: xor_expr ('|' xor_expr)*
...
power: atom trailer* ['**' factor]
trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
So a function call is a power is a factor is a term is an arith_expr
is a shift_expr is an and_expr is a xor_expr is an expr is a comparison
is a not_test is an and_test is a test.
> <exprlst> is a list of names, not arbitrary expressions
No, it's more than that. I can also be
a, (b, c, (d, e))
But as I said: there are further (semantical) constraints what
kind of expression you can have there.
Regards,
Martin
More information about the Python-Dev
mailing list