[issue44177] Unable to get the else while parsing through AST module

2021-05-20 Thread Eric V. Smith
Eric V. Smith added the comment: There's no actual code associated with the "else" line, so there's no way to get the line number. dis.dis(sample_data) might give you some insight. Since this all works as designed, I'm going to close this issue. You might get more help on StackOverflow or si

[issue44177] Unable to get the else while parsing through AST module

2021-05-20 Thread Pablo Galindo Salgado
Change by Pablo Galindo Salgado : -- nosy: -pablogsal ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:

[issue44177] Unable to get the else while parsing through AST module

2021-05-20 Thread Bikram Singh Mehra
Bikram Singh Mehra added the comment: Hi Eric, I have tried the action plan suggested by you in your last comment, but below are my logs and still I am unable to get lineno for else statement. The respective line no for each line are below 1 2 if num > 0: 3 print("Positive n

[issue44177] Unable to get the else while parsing through AST module

2021-05-19 Thread Eric V. Smith
Eric V. Smith added the comment: It's in the AST. >>> tree.body[0].orelse[0].orelse[0].lineno 7 To see it with dump, use: ast.dump(tree, include_attributes=True) Which, after some reformatting, gives: Module(body=[If(test=Compare(left=Name(id='num', ctx=Load(), lineno=2, col_offset=3, end

[issue44177] Unable to get the else while parsing through AST module

2021-05-19 Thread Bikram Singh Mehra
Bikram Singh Mehra added the comment: Hi Eric, Thanks for the quick response here, I have gone through your suggestion but following that I am able to print the else node data i.e. "print("Negative number")" but unable to get the lineno of that else child node. Could you please confirm if

[issue44177] Unable to get the else while parsing through AST module

2021-05-19 Thread Eric V. Smith
Eric V. Smith 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='pri

[issue44177] Unable to get the else while parsing through AST module

2021-05-19 Thread Bikram Singh Mehra
New submission from Bikram Singh Mehra : Hi Team, I was parsing python file using AST module but ran into a situation where the else statement is not found in the parsed data. - Module used is: ast - In the parsed data I can see "if" followed by "elif"