Python Forum
How Do I Determine indentation in AST?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How Do I Determine indentation in AST?
#3
(Jul-01-2018, 02:20 PM)buran Wrote: PEP 257 should help
https://www.python.org/dev/peps/pep-0257...ndentation

Thanks for the fast reply. The document you pointed me to would be good if I were writing a docstring processing tool that simply looks at an existing source file to pick out the docstrings, but I am attempting to write a docstring generation tool where I would either generate docstrings from scratch or add more documentation to existing docstrings. I do not see how the code in the referenced section applies in that case unless I wanted to create my own Abstract Syntax Trees. I would much rather use the existing ast module (and others if necessary) to get the required information.

I have found that ast nodes have a member called 'lineno' that contains the line number of the node in the source file, so I may be able to search the source code starting at the line after looking for an existing docstring and figure out the indentation from there. I think a simple search for """ or ''' before the next node will be enough for that.

I will code that to determine if I can get it working. If there is a simpler solution, I would certainly appreciate hearing about it.
Reply


Messages In This Thread
How Do I Determine indentation in AST? - by jimo - Jul-01-2018, 02:14 PM
RE: How Do I Determine indentation in AST? - by jimo - Jul-01-2018, 04:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to determine pen color from an image? robie972003 2 2,477 Mar-24-2019, 10:06 PM
Last Post: robie972003
  determine if an number is in a list Dbeah 7 3,862 Nov-06-2018, 12:11 PM
Last Post: buran
  determine if an number is in a list Dbeah 1 2,289 Nov-04-2018, 04:50 PM
Last Post: stullis
  how to determine if an object is a number Skaperen 6 4,087 Jul-11-2018, 08:18 PM
Last Post: Skaperen
  Determine whether a method was overridden porton 6 6,236 Nov-14-2016, 09:51 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020