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

holger krekel pyth at devel.trillke.net
Mon Feb 10 06:26:34 EST 2003


Andrew Koenig wrote:
> Erik> I'm just saying saying that if you want a conditional expression
> Erik> to be legal as a standalone statement, that requires a parser
> Erik> change in how if statements are handled -- i.e., you have to
> Erik> look ahead and see "oh, there's an `else:' on this same line, so
> Erik> this is the conditional operator as a standalone statement, not
> Erik> an if statement.  But ...
> 
> Right.  That's one reason I don't want a conditional expression to be
> legal as a standalone statement.

I think it's insane to make up such special cases just to get
some syntax in.  For starters, you would break Quixote (web application
framework) because they compile Python so that an expression as a
statement gets send to some object.  Breaking uniformity needs
to be avoided as much as possible.  Especially if the *real need*
for the whole construct is debatable. 

> >> If you parenthesize it:
> 
> >> (if debug: sys.stderr.write('got here\n') else: None)
> 
> >> then the "if" is no longer the first token in the statement, so it
> >> introduces an if-expression.  No problem.

Special cases aren't special enough ...  

We all like Python's easy grammar and uniformity, don't we? 

    holger





More information about the Python-list mailing list