2012-03-02 76 views
14

我正在清理Python代碼文檔,並決定使用sphinx-doc,因爲它看起來不錯。我喜歡我怎麼能引用其他類和方法與像標籤:如何用sphinx-apidoc文檔化Python函數參數

:class:`mymodule.MyClass` About my class. 
:meth:`mymodule.MyClass.myfunction` And my cool function 

我想弄清楚,雖然如何在函數參數名的文件,因此,如果我有這樣一個功能:

def do_this(parameter1, parameter2): 
    """ 
    I can describe do_this. 

    :something?:`parameter1` And then describe the parameter. 

    """ 

這樣做的最佳做法是什麼?

更新:

正確的語法是:

def do_this(parameter1, parameter2): 
    """ 
    I can describe do_this. 

    :something parameter1: And then describe the variable 
    """ 
+1

這些被稱爲「信息字段列表」。另見http://stackoverflow.com/questions/4547849/good-examples-of-python-docstrings-for-sphinx – gotgenes 2012-03-02 17:44:42

+0

查看[Napolean](http://www.sphinx-doc.org/en/stable /ext/napoleon.html)Sphinx的擴展,它允許[Google或Numpy樣式]中的文檔字符串(http://www.sphinx-doc.org/en/stable/ext/napoleon.html#google-vs- numpy),這兩者看起來都很好,就是那個普通的獅身人面像。 – cbare 2016-03-11 00:59:55

+0

也感興趣:http://www.pydev.org/manual_adv_type_hints.html – 2017-03-13 09:25:56

回答

9

通常 「函數變量」 被稱爲參數)。

它記錄在這裏:http://sphinx.pocoo.org/domains.html#signatures

答案是:param ________

編輯聲明:我從來沒有使用過或聽說過獅身人面像的...這篇文章主要是一個「去搜一下字「。希望它有幫助。

+0

謝謝......我正在尋找錯誤的東西。我在某個時候嘗試過param,但不斷髮現錯誤,並沒有意識到語法不是:param:'variable1',但是:param variable1: – 2012-03-02 14:14:29

+1

http://sphinx-doc.org/domains.html#id1和https://pythonhosted.org/an_example_pypi_project/sphinx.html#function-definitions – ddotsenko 2015-01-01 17:27:34

+1

用於記錄複雜參數(列表,字典等)的約定 - https://www.jetbrains.com/pycharm/webhelp/type-hinting-in -pycharm.html – ddotsenko 2015-01-01 17:46:56