如何用Python编写模块文档?

如何用Python编写模块文档?,python,documentation,python-module,Python,Documentation,Python Module,就这样。如果要记录函数或类,可以在定义后面放一个字符串。例如: def foo(): """This function does nothing.""" pass 但是模块呢?如何记录file.py的功能?很简单,您只需在模块顶部添加一个docstring。对于包,您可以在\uu init\uuuuuuuuuy.py中记录它。 对于模块,只需在模块文件中添加docstring即可 所有信息都在这里:你用完全相同的方法来做。将字符串作为模块中的第一条语句放入。将您的docstri

就这样。如果要记录函数或类,可以在定义后面放一个字符串。例如:

def foo():
    """This function does nothing."""
    pass

但是模块呢?如何记录file.py的功能?

很简单,您只需在模块顶部添加一个docstring。

对于包,您可以在
\uu init\uuuuuuuuuy.py
中记录它。 对于模块,只需在模块文件中添加docstring即可


所有信息都在这里:

你用完全相同的方法来做。将字符串作为模块中的第一条语句放入。

将您的docstring添加为第一条语句

对于软件包,您可以将您的docstring添加到
\uuu init\uuuu.py

下面是一个关于如何记录模块的示例。基本上有一个关于模块的信息,如何执行它,以及关于模块级变量和ToDo项列表的信息

"""Example Google style docstrings.

This module demonstrates documentation as specified by the `Google
Python Style Guide`_. Docstrings may extend over multiple lines.
Sections are created with a section header and a colon followed by a
block of indented text.

Example:
    Examples can be given using either the ``Example`` or ``Examples``
    sections. Sections support any reStructuredText formatting, including
    literal blocks::

        $ python example_google.py

Section breaks are created by resuming unindented text. Section breaks
are also implicitly created anytime a new section starts.

Attributes:
    module_level_variable1 (int): Module level variables may be documented in
        either the ``Attributes`` section of the module docstring, or in an
        inline docstring immediately following the variable.

        Either form is acceptable, but the two should not be mixed. Choose
        one convention to document module level variables and be consistent
        with it.

Todo:
    * For module TODOs
    * You have to also use ``sphinx.ext.todo`` extension

.. _Google Python Style Guide:   
http://google.github.io/styleguide/pyguide.html

"""

module_level_variable1 = 12345

def my_function():   
    pass 
... 
...

对于PyPI软件包:

如果在\uuuu init\uuuu.py文件中添加这样的文档字符串,如下所示

"""
Please refer to the documentation provided in the README.md,
which can be found at gorpyter's PyPI URL: https://pypi.org/project/gorpyter/
"""

# <IMPORT_DEPENDENCIES>

def setup():
    """Verify your Python and R dependencies."""

注意,我的帮助
DESCRIPTION
是由文件顶部的第一个docstring触发的。

这是eclipse在创建新模块时自动执行的操作。我刚刚发现:希望对您有用。
"""
Please refer to the documentation provided in the README.md,
which can be found at gorpyter's PyPI URL: https://pypi.org/project/gorpyter/
"""

# <IMPORT_DEPENDENCIES>

def setup():
    """Verify your Python and R dependencies."""
DESCRIPTION
    Please refer to the documentation provided in the README.md,
    which can be found at gorpyter's PyPI URL: https://pypi.org/project/gorpyter/


FUNCTIONS
    setup()
        Verify your Python and R dependencies.