"Weird" Indentation? (Or: is there a for...else construct?)

Andreas Waldenburger geekmail at usenot.de
Sat Feb 7 09:21:22 EST 2009


I've found something in the spirit of the following (in the epydoc
sources, if you care):

if True:
    print "outer if"
    for t in range(2):
        if True:
            print "for if"
    else:
        print "phantom else"

For the life of me I can't place the "else". Which if clause does it
belong to? None, it would seem from running the above snippet:

outer if
For if
For if
Phantom else

It seems that there is a for...else construct. Replacing the inner if
with pass seems to confirm this. The else clause is still executed.

What's broken here: Python or my brain?

/W

-- 
My real email address is constructed by swapping the domain with the
recipient (local part).



More information about the Python-list mailing list