2013-10-09 35 views
3

我剛剛開始與獅身人面像,並願意學習。Python中的獅身人面像autodoc功能模塊內

我想分解我的各種功能到我的index.rst文件中的不同部分。所以每個函數都有自己的頭文件。

因此,舉例來說,如果我有一個名爲test.py一個Python文件,該文件中我有2個功能

def foo(): 
    """This prints bar""" 
    print("bar") 

def bar(): 
    """This prints foo""" 
    print("foo") 

我怎麼會內index.rst我test.py文件中分離出來的2個功能。

:mod:`test` -- foo 
.. automodule:: test.foo 
    :members: 
    :undoc-members: 
    :show-inheritance: 
:mod:`test` -- bar 
.. automodule:: test.bar 
    :members: 
    :undoc-members: 
    :show-inheritance: 

如果我能弄清楚如何分離函數,使它在index.html中看起來更乾淨,那將非常棒!因爲它是現在的輸出不是很乾淨,如果我只是運行下面的以下內容:

:mod:`test` -- these are my functions 
-------------------------------------------- 
.. automodule:: test 
    :members: 
    :undoc-members: 
    :show-inheritance: 

回答

6

您可以使用autofunction。像這樣:

The test module 
=============== 

The test module contains... 

.. currentmodule:: test 

The foo function 
---------------- 

.. autofunction:: foo 

The bar function 
---------------- 

.. autofunction:: bar