如何使用pydoc生成自己代码的文档?

时间:2020-08-03 09:20:39

标签: python pydoc

我需要使用Pydoc生成文档。 我已经使用Docstrings编写了一些解释,例如以下示例

def function():
    '''
    this function does something
    :return: returns nothing
    '''

然后,我尝试通过Windows PowerShell查看我的文档。因此,我使用

python -m pydoc myfile.py

但是我得到的只是以下错误:

problem in myFile - IndexError: list index out of range

我的脚本确实需要更多参数,例如:

python -m pydoc myfile.py argument1 argument2

但是随后我收到以下错误:

No Python Documentation found for myfile.
No Python Documentation found for argument1.
No Python Documentation found for argument2.

1 个答案:

答案 0 :(得分:0)

问题不在于pydoc,而在于您编写的Python代码。错误

problem in myFile - IndexError: list index out of range

意味着在代码中的某个位置,您正在尝试按索引访问列表元素。

mylist = [1, 2, 3]
mylist[0] # should yield "1"
mylist[1] # should yield "2"
mylist[2] # should yield "3"

但是您使用的索引无效。

mylist = [1, 2, 3]
mylist[3] # the index 3 is out of range for this list, so it will give you a IndexError

确保用于访问列表的所有索引值都在0到列表的长度减去1之间,然后在命令行中运行它:

python -m pydoc myfile

相关问题