Pergunta

É isso.Se você deseja documento de uma função ou de uma classe, você coloca uma cadeia de caracteres apenas depois da definição.Por exemplo:

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

Mas o que dizer de um módulo?Como posso documento que file.py não?

Foi útil?

Solução

Para os pacotes, você pode documentar-lo em __init__.py.Para os módulos, você pode adicionar uma docstring simplesmente no módulo arquivo.

Todas as informações estão aqui: http://www.python.org/dev/peps/pep-0257/

Outras dicas

Adicione o seu docstring como o primeira instrução no módulo.

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

import foo

# ...

Para pacotes, você pode adicionar o seu docstring para __init__.py.

Aqui está um Exemplo, O Google Estilo Python Docstrings sobre como o módulo pode ser documentado.Basicamente, há uma informação sobre um módulo, de como executá-lo e obter informações sobre variáveis de nível de módulo e lista de itens para Fazer.

"""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 
... 
...

Você fazê-lo exatamente da mesma forma.Colocar uma seqüência de caracteres como a primeira instrução no módulo.

É fácil, basta você adicionar uma docstring no topo do módulo.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top