py: Fix compiling of nested while/for and exception handler.

Addresses issue #912.