如何让 Pydoc 以特定顺序记录我的功能?

How to make Pydoc document my functions in a specific order?

我想指定 Pydoc 记录我的函数的顺序。我不确定 Pydoc 如何在生成的文档中对函数进行排序——这肯定不是模块中的文本顺序。

这很有用,因为我想首先指定要记录的 printUsage() 函数。

"""
Sample module docstring
"""

def printUsage():
    """
    Command line usage: python my_module.py -i path/to/input_file.c
    If calling my_function() directly, pass the path/to/input_file.c as an arg.
    """
    print(printUsage.__doc__)

...

这样当用户查看 my_module 的文档字符串时,他可以快速了解如何使用它。

查看 sourcecode:

看起来模块文档存储为字典,因此当它们遍历它们时,它会创建随机顺序:

def namelink(self, name, *dicts):
    """Make a link for an identifier, given name-to-URL mappings."""
    for dict in dicts:
        if name in dict:
            return '<a href="%s">%s</a>' % (dict[name], name)