2011-02-08 9 views
6

Sto programmando una nuova libreria Python, che richiede una buona documentazione. Quali sono i buoni modi per documentare una tale libreria? Preferirei un metodo che genera una documentazione completa in html.Come documentare un progetto Python?

+0

La documentazione HTML autogenerata è la cosa peggiore che sia mai accaduta nella documentazione, conducendo invariabilmente a tali aborti come [questo] (http://www.alsa-project.org/alsa-doc/alsa-lib/). –

+4

Documentazione HTML autogenerata male> nessuna documentazione –

+0

Penso che sia possibile generare una documentazione HTML utile. E non voglio qualcosa come la documentazione ALSA, piuttosto che qualcosa come la documentazione [Sphinx] (http://sphinx.pocoo.org/contents.html). – svenwltr

risposta

10

L'utilizzo di docstrings ovunque è il primo passo. Quindi è possibile utilizzare uno qualsiasi degli strumenti di generazione di documentazione Python per generare documentazione di qualità. È ciò che python.org fa, usando Sphinx.

Ma usando docstring ha anche il vantaggio aggiuntivo di essere utile per i programmatori proprio nel interprete così:

>>> help(dir) 
Help on built-in function dir in module __builtin__: 

dir(...) 
    dir([object]) -> list of strings 

    If called without an argument, return the names in the current scope. 
    Else, return an alphabetized list of names comprising (some of) the attributes 
    of the given object, and of attributes reachable from it. 
    If the object supplies a method named __dir__, it will be used; otherwise 
    the default dir() logic is used and returns: 
     for a module object: the module's attributes. 
     for a class object: its attributes, and recursively the attributes 
     of its bases. 
     for any other object: its attributes, its class's attributes, and 
     recursively the attributes of its class's base classes. 

Tutto questo deriva dal docstring della funzione built-dir(), e diventa piuttosto-stampato bene tramite la funzione integrata help().

+1

So Sphinx genera la documentazione da docstring? – svenwltr

+0

Non * solo * estrae da docstrings ma l'estensione Autodoc lo fa per te: http://sphinx.pocoo.org/tutorial.html#autodoc –

+0

Great! Daro un'occhiata per quello. – svenwltr

Problemi correlati