Jul-01-2018, 04:03 PM
(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.