如何为pydoc注释参数

帕特里克

有没有一种方法可以注释函数的参数,以使其能够被pydoc库识别?

即pydoc的文档字符串是什么?

是的

pydoc无法识别文档字符串中的“结构化”元素,它仅按原样输出文档字符串。有关示例,请参见PEP-257

如果需要“格式化”的文档,则应使用其他文档生成器,例如Sphinxpdoc

函数的参数必须记录在函数docstring中。这是从此答案得到的示例

"""
This example module shows various types of documentation available for use
with pydoc.  To generate HTML documentation for this module issue the
command:

    pydoc -w foo

"""

class Foo(object):
    """
    Foo encapsulates a name and an age.
    """
    def __init__(self, name, age):
        """
        Construct a new 'Foo' object.

        :param name: The name of foo
        :param age: The ageof foo
        :return: returns nothing
        """
        self.name = name
        self.age

def bar(baz):
    """
    Prints baz to the display.
    """
    print baz

if __name__ == '__main__':
    f = Foo('John Doe', 42)
    bar("hello world")

下面是另一个更明显的例子,如果你想利用与多个参数的描述,如修改案文:type param::rtype:采取从这里

"""
The ``obvious`` module
======================

Use it to import very obvious functions.

:Example:

>>> from obvious import add
>>> add(1, 1)
2

This is a subtitle
-------------------

You can say so many things here ! You can say so many things here !
You can say so many things here ! You can say so many things here !
You can say so many things here ! You can say so many things here !
You can say so many things here ! You can say so many things here !

This is another subtitle
------------------------

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

"""

def add(a, b):
    """
    Adds two numbers and returns the result.

    This add two real numbers and return a real result. You will want to
    use this function in any place you would usually use the ``+`` operator
    but requires a functional equivalent.

    :param a: The first number to add
    :param b: The second number to add
    :type a: int
    :type b: int
    :return: The result of the addition
    :rtype: int

    :Example:

    >>> add(1, 1)
    2
    >>> add(2.1, 3.4)  # all int compatible types work
    5.5

    .. seealso:: sub(), div(), mul()
    .. warnings:: This is a completly useless function. Use it only in a 
              tutorial unless you want to look like a fool.
    .. note:: You may want to use a lambda function instead of this.
    .. todo:: Delete this function. Then masturbate with olive oil.
    """
    return a + b

您还可以使用不同的文档字符串格式(例如GoogleNumpy),我建议!使您的文档字符串更清晰。

希望这可以帮助!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何为Google Cloud Endpoints方法生成pydoc文档?

来自分类Dev

如何为Javadoc注释上色

来自分类Dev

如何为带有宏注释的Scala case类添加无参数构造函数?

来自分类Dev

如何为“ AsRef”提供类型注释?

来自分类Dev

如何为Flow注释此功能

来自分类Dev

如何为空集提供类型注释?

来自分类Dev

如何为kapt注释伪造多遍

来自分类Dev

如何为PoPieChartRep设置注释颜色?

来自分类Dev

如何为 sluggable 列注释 @groups

来自分类Dev

如何扩展Jersey的参数注释?

来自分类Dev

如何模拟jcabi注释参数

来自分类Dev

如何为MotionEvent添加参数

来自分类Dev

如何获取带注释的方法参数及其注释

来自分类Dev

如何获得在注释处理器的注释参数

来自分类Dev

如何取消对注释参数的弃用警告

来自分类Dev

如何将注释作为参数传递?

来自分类Dev

如何正确运行注释功能参数

来自分类Dev

如何避免到处重复相同的注释参数?

来自分类Dev

如何使用参数转发注释高阶函数

来自分类Dev

如何为HTML模板创建大样式注释

来自分类Dev

如何为主要模式定义注释语法?

来自分类Dev

如何为要输出到LogCat的类编写注释?

来自分类Dev

如何为耶拿模型添加注释?

来自分类Dev

如何为Jenkins构建检索SVN Changeset注释?

来自分类Dev

如何为字段中的注释生成Dart代码?

来自分类Dev

如何为进入队列的变量添加变量类型注释?

来自分类Dev

如何为git pull merge消息提供注释

来自分类Dev

您如何为Swagger注释嵌套的Java类?

来自分类Dev

如何为SyntaxNode添加自定义语法注释?