How to generate documentation using Pydoc

隐身守侯 提交于 2019-12-23 05:02:09

问题


I need to generate documentation from comments using pydoc. What are the basic steps to do that?


回答1:


If you really want to use Pydoc, you can simply do in a terminal:

$ pydoc -w myproject

This will generate an old-school HTML documentation from doctrings. Note that Pydoc is the module used in Python since 2.1 for the help() function. It will retrieve the docstrings which are NOT comments. You should describe your functions using docstrings.

But it is a kind of old-school using Pydoc for documentation generating. The popular tool to do that in Python is Sphinx. But you'll need to format your docstrings in a particular format as reStructuredText.

You could also use pdoc, which auto-extracts documentation from your docstrings (i.e. public API) and supports markdown, numpydoc, google-style docstrings format and some reStructuredText directives.

Have a look here to get some information concerning docstrings formatting.

You can also use Pyment to generate docstring skeletons or convert existing ones to a particular format.




回答2:


Alternatively, if you want a simple text file instead of HTML, you can redirect the console output to a file with this simple command:

$ pydoc myproject > helpfile.txt

This file can be printed or uploaded to Github without too much additional effort.



来源:https://stackoverflow.com/questions/26587763/how-to-generate-documentation-using-pydoc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!