用于打印给定 Python 文件中的文档字符串的命令行是什么?
我以为有类似的东西:
$ python --showhelp foo.py
Name Help
--------------------------------------------------
bar This is the docstring for bar().
baz This is the docstring for baz().
答案1
找到了:pydoc
对于此示例文件:
# foo.py
def bar():
"""this is the docstring for bar()"""
print 'hello'
def baz():
"""this is the docstring for baz()"""
print 'world'
您可以使用以下命令将文档字符串打印到标准输出:
$ pydoc ./foo.py
Help on module foo:
NAME
foo
FILE
/path/to/foo.py
FUNCTIONS
bar()
this is the docstring for bar()
baz()
this is the docstring for baz()
您还可以生成 HTML 帮助文件:
$ pydoc -w ./foo.py
wrote foo.html
看起来像这样: