Eric V. Smith <e...@trueblade.com> added the comment:

Formatting the result, I get:
Module(body=[If(test=Compare(left=Name(id='num', ctx=Load()),
                             ops=[Gt()],
                             comparators=[Constant(value=0, kind=None)]),
                body=[Expr(value=Call(func=Name(id='print', ctx=Load()),
                                      args=[Constant(value='Positive number',
                                                     kind=None)],
                                      keywords=[]))],
                orelse=[If(test=Compare(left=Name(id='num', ctx=Load()),
                                        ops=[Eq()],
                                        comparators=[Constant(value=0, 
kind=None)]),
                           body=[Expr(value=Call(func=Name(id='print', 
ctx=Load()),
                                                 args=[Constant(value='Zero', 
kind=None)],
                                                 keywords=[]))],
                           orelse=[Expr(value=Call(func=Name(id='print', 
ctx=Load()),
                                                   
args=[Constant(value='Negative number', kind=None)],
                                                   keywords=[]))])])],
       type_ignores=[])

You'll have to extract the "else" part by walking the tree yourself.

> I was parsing python file using AST module but ran into a situation where the 
> else statement is not found in the parsed data.

It is in the parsed data, though. Just not directly in the "If" node.

----------
nosy: +eric.smith

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44177>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to