For review: PEP 308 - If-then-else expression

Andrew Koenig ark at research.att.com
Mon Feb 10 15:03:26 EST 2003


James> I think the concern is that a statement in Python may consist
James> of or begin with an expression and thus the leading keyword
James> alone is not enough to tell what is going on.

In my grammar proposal, I'm defining it that way: Any statement that
begins with "if" is an if-statement, not an if-expression treated
as a statement.

James> I am looking into this more closely to confirm but I don't
James> think it's a problem for the parser.

If you can find another way of doing it that's more general and/or
permissive, that's fine with me.

James> I expect that if you  said something like:

James> 	if test: expr1 else: expr2

James> That would parse as an expression because of the LACK of newlines.

James> 	if test:
James> 		expr1
James> 	else:
James> 		expr2

James> Would be parsed as an if-statement, with expr1 and expr2 also
James> being seen as statements.

I'm skeptical that this is possible, but if you can figure out a way to
do it, that would be fine with me.





More information about the Python-list mailing list