我理解Python是如何工作的,我经常使用docstrings来访问函数docstring。但是,我不知道如何使用render_doc来访问帮助主题,例如help("UNARY")。我甚至不知道这样的docstring会在哪里存在。是否有一种方法可以( a)使用pydoc访问帮助主题,或者b)另一种方法来捕获变量中的帮助文本?
help("UNARY") # prints help to console
import pydoc
pydoc.help("UNARY") # prints help to console
test = pydoc.render_doc("str") # writes help to variable
test = pydoc.render_doc("UNARY") # ERROR
pydoc.help("UNARY") # prints help to console
test = pydoc.help("UNARY") # prints help to console, 'test' is empty发布于 2017-07-25 06:09:07
pydoc将在命令行中工作。使用下面的命令为当前位置的python模块生成html文档。
C:>python -m pydoc -w sys编写了sys.html
但是pydoc命令不能用于关键字和主题。
请参考https://svn.python.org/projects/sandbox/trunk/setuptools/pydoc.py以了解主题和关键字的列表。
https://stackoverflow.com/questions/45294543
复制相似问题