2008-09-04 41 views
44

Eso es todo. Si desea documentar una función o una clase, coloque una cadena justo después de la definición. Por ejemplo:¿Cómo puedo documentar un módulo en Python?

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

¿Pero qué tal un módulo? ¿Cómo puedo documentar lo que hace un archivo file.py?

+2

Mira, acabo de encontrar esto: http://docs.python.org/devguide/documenting.html Esperanza ser útil para usted. –

Respuesta

36

Para los paquetes, puede documentarlo en __init__.py. Para los módulos, puede agregar una docstring simplemente en el archivo del módulo.

Toda la información está aquí: http://www.python.org/dev/peps/pep-0257/

4

Es fácil, simplemente agrega un docstring en la parte superior del módulo.

6

Usted lo hace de la misma manera exacta. Ponga una cadena como la primera declaración en el módulo.

+0

Esto es lo que eclipse hace automáticamente cuando crea un nuevo módulo. – Rivka

28

Agregue su docstring como first statement in the module.

ya que me gusta ver un ejemplo:

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

import foo 

# ... 
2

He aquí un Example Google Style Python Docstrings sobre cómo módulo puede ser documentada. Básicamente, hay información sobre un módulo, cómo ejecutarlo e información sobre las variables de nivel de módulo y la lista de elementos 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 
... 
... 
Cuestiones relacionadas