2

While Python does not officially support docstrings for global variables, it is common to add them anyway:

debug = False
'''Set debug to True to see lots of intermediate results'''

Docstring for variable explains that Python does not directly offer access, but Sphinx is able to pull these out of a module. For something I am working on, I would like to access them as well. I think the ast module can do this. Anyone have any example code (using ast or other standard libraries) that can provide docstrings for variables defined in a module?

1

1 Answer 1

1

The astor library parses the entire AST and will reconstitute Python. The version on github is well ahead of the Pypi version, so you should clone it from there.

The tree processing is fairly easy to follow -- you should be able to modify it to only give you the docstrings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.