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

James J. Besemer jb at cascade-sys.com
Mon Feb 10 14:32:00 EST 2003


Andrew Koenig wrote:
> 
> If the "if" in "if something:" is the first token in its statement,
> then what follows the : is a suite; otherwise it's an expression.
> 

I think the concern is that a statement in Python may consist of or begin 
with an expression and thus the leading keyword alone is not enough to tell 
what is going on.

I am looking into this more closely to confirm but I don't think it's a 
problem for the parser.

I expect that if you  said something like:

	if test: expr1 else: expr2

That would parse as an expression because of the LACK of newlines.

	if test:
		expr1
	else:
		expr2

Would be parsed as an if-statement, with expr1 and expr2 also being seen as 
statements.

--jb


-- 
James J. Besemer		503-280-0838 voice
2727 NE Skidmore St.		503-280-0375 fax
Portland, Oregon 97211-6557	mailto:jb at cascade-sys.com
				http://cascade-sys.com	







More information about the Python-list mailing list