PEP 308: Alternative conditional operator forms

holger krekel pyth at devel.trillke.net
Mon Feb 10 20:22:51 EST 2003


Erik Max Francis wrote:
> 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.

Not true but Andrew Koenig (probably) found a way to make this happen
(changing the grammar and adding to it). 

    holger





More information about the Python-list mailing list