For review: PEP 308 - If-then-else expression
pyth at devel.trillke.net
Tue Feb 11 00:35:51 CET 2003
John La Rooy wrote:
> On Mon, 10 Feb 2003 12:26:34 +0100
> holger krekel <pyth at devel.trillke.net> wrote:
> > > >> 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
> Indeed. Could we perhaps consider making if an expression in every case and
> have it evaluate to the last expression in the block so we could write
> print if x>0:
> ### possibly several lines of code here...
> ### and here too...
the general problem is that it is not easy to switch from "block" to
"expression mode" in the parser. You usually are in either one and
can't backtrack to the other one.
More information about the Python-list