Docstring for variable

前端 未结 9 1907
予麋鹿
予麋鹿 2021-01-31 13:35

Is it posible to use docstring for plain variable? For example I have module called t

def f():
    \"\"\"f\"\"\"

l = lambda x: x
\"\"\"l\"\"\"


        
相关标签:
9条回答
  • 2021-01-31 14:15

    Some python documentation scripts have notation that can be use in the module/classes docstring to document a var.

    E.g. for spinx, you can use :var and :ivar. See this document (about half-way down).

    0 讨论(0)
  • 2021-01-31 14:16

    Sphinx has a built-in syntax for documenting attributes (i.e. NOT the values as @duncan describes). Examples:

    #: This is module attribute
    x = 42
    
    class MyClass:
    
        #: This is a class attribute
        y = 43
    

    You can read more in the Sphinx docs: http://www.sphinx-doc.org/en/1.4.8/ext/autodoc.html#directive-autoattribute

    ...or in this other question: How to document a module constant in Python?

    0 讨论(0)
  • 2021-01-31 14:19

    Epydoc allows for docstrings on variables:

    While the language doesn't directly provides for them, Epydoc supports variable docstrings: if a variable assignment statement is immediately followed by a bare string literal, then that assignment is treated as a docstring for that variable.

    Example:

    class A:
        x = 22
        """Docstring for class variable A.x"""
    
        def __init__(self, a):
            self.y = a
            """Docstring for instance variable A.y
    
    0 讨论(0)
提交回复
热议问题