This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.smith
Recipients bikrammehra97, eric.smith, lys.nikolaou, pablogsal
Date 2021-05-19.11:31:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1621423876.15.0.179552341486.issue44177@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-05-19 11:31:16eric.smithsetrecipients: + eric.smith, lys.nikolaou, pablogsal, bikrammehra97
2021-05-19 11:31:16eric.smithsetmessageid: <1621423876.15.0.179552341486.issue44177@roundup.psfhosted.org>
2021-05-19 11:31:16eric.smithlinkissue44177 messages
2021-05-19 11:31:16eric.smithcreate