当前位置:  开发笔记 > 编程语言 > 正文

如何在Python中记录模块?

如何解决《如何在Python中记录模块?》经验,为你挑选了4个好方法。

而已.如果要记录函数或类,请在定义之后放置一个字符串.例如:

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

但是模块怎么样?如何记录file.py的作用?



1> Brad Koch..:

将docstring添加为模块中的第一个语句.

"""
Your module's verbose yet thorough docstring.
"""

import foo

# ...

对于包,您可以将文档字符串添加到__init__.py.



2> Grégoire Cac..:

对于包,您可以将其记录下来__init__.py.对于模块,您只需在模块文件中添加docstring即可.

所有信息都在这里:http://www.python.org/dev/peps/pep-0257/



3> Vlad Bezden..:

以下是关于如何记录模块的Google样式Python文档字符串示例.基本上有一个关于模块的信息,如何执行它以及有关模块级变量和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 
... 
...



4> Chris Upchur..:

你这样做完全一样.将字符串作为模块中的第一个语句.

推荐阅读
黄晓敏3023
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有