For review: PEP 308 - If-then-else expression
rnd at onego.ru
Mon Feb 10 06:43:38 CET 2003
On Mon, 10 Feb 2003, Andrew Koenig wrote:
>Erik> Well, it's unambiguous, but it could require some extra
>Erik> lookahead. I'm no Python parser expert, but it seems to me the
>Erik> only case this happens is when the conditional expression is
>Erik> used as a standalone statement, e.g.
>Erik> if debug: sys.stderr.write('got here\n') else: None
>Why is extra lookahead required here? The "if" is the first token in
>the statement, so it can only denote an if-statement, not an
In Python, expression is a standalone statement. So in case of
if expr1: expr2 else: expr3
the parser will notice the difference only at "else".
>Then we look at the grammar, which says that
>an if-statement in this case is
> "if" expression ":" suite "else" ":" suite
>and we see that a suite must end in a newline.
Sincerely yours, Roman Suzi
rnd at onego.ru =\= My AI powered by Linux RedHat 7.3
More information about the Python-list