Why no 'elif' in try/except?

D-Man dsh8290 at rit.edu
Mon Jun 4 15:36:35 EDT 2001


On Mon, Jun 04, 2001 at 08:03:21PM +0200, Boyd Roberts wrote:
| "Marcin 'Qrczak' Kowalczyk" <qrczak at knm.org.pl> a écrit dans le message news: slrn.pl.9hnbs9.4l5.qrczak at qrnik.zagroda...
| > I don't understand only one thing. Why it is spelled 'elif' and not
| > 'else if'?
| 
| may have been influenced by 'elif' from the Bourne shell as well as
| the fact that it's simpler to parse, given it's one token and not
| two (less look ahead).

I think it is also related to Python's block structure.  If it was
spelled "else if" in the same way C/C++/Java spell it, then your code
would have to look like 

if <expr> :
    <statements>
else if <expr> :
        <statements>
    else if <expr> :
            <statements>
        else if <expr> :
                <statements>
            else :
                <statements>

as this is exactly what the parse tree from C/C++/Java look like.  The
simple act of indenting "improperly" gives the proper look to the
form.  I will also point out, before someone else does, that this
isn't exactly correct Python indentation because there is no ':' after
the 'else' and only simple statements can occur on the same line (the
'if's would need to be on the next line).

-D





More information about the Python-list mailing list