PEP 308: Alternative conditional operator forms

Erik Max Francis max at alcyone.com
Mon Feb 10 20:00:49 EST 2003


John Roth wrote:

> Because you've got a major ambiguity if the statement begins
> with an "if". That comment is in the PEP.

It's only an ambiguity if you insist that the two forms meet in the
middle.  There's no reason to make this happen; simply keep things as
is, where an `if' keyword starting a statement always means an if
statement.  Thus

	if C: x else: y

as a standalone statement is SyntaxError (perhaps with a slightly more
helpful message attached).  If you really wanted the conditional
operator, surround it in parentheses.

No ambiguity, since an if statement cannot possibly be preceded by an
open parenthesis.  It only involves additions to the grammar, no
changes.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Whoever contends with the great sheds his own blood.
\__/ Sa'di
    Polly Wanna Cracka? / http://www.pollywannacracka.com/
 The Internet resource for interracial relationships.




More information about the Python-list mailing list