2016-09-29 55 views
1

Python docs表示「用於Python文檔的標記是reStructuredText」。我的問題是:塊應該如何寫入來顯示多個返回值?如何在Python 2中使用reStructuredText記錄多個返回值?

def func_returning_one_value(): 
    """Return just one value. 

    :returns: some value 
    :rtype: str 
    """ 

def func_returning_three_values(): 
    """Return three values. 

    How do I note in reStructuredText that three values are returned? 
    """ 

我發現用新結構化的Python文檔一個tutorial,但它並沒有用於記錄多個返回值的例子。 Sphinx docs on domains談到returnsrtype,但不談論多個返回值。

+0

似乎任何東西都與docstrings一樣,只要它在整個項目中清晰簡潔並一致。寫一些適合你的目的的東西。 [PEP 257](https://www.python.org/dev/peps/pep-0257/)有一些廣泛的約定。查看計算機上的python py文件,看看開發人員如何做到這一點。 – wwii

+1

像[os.walk()](https://github.com/python/cpython/blob/a237032d7732bd9142e3802b77767d342bb30870/Lib/os.py#L277)它返回多個東西。 – wwii

回答

3

正如wwi在評論中提到的那樣,使用的詳細格式沒有嚴格定義。

對於我自己,我通常使用上面使用的Field List表示法。它支持換行符,所以只要打破你覺得有必要的地方

def my_func(param1, param2): 
    """ 
    This is a sample function docstring 

    :param param1: this is a first param 
    :param param2: this is a second param 
    :returns: tuple (result1, result2) 
     WHERE 
     str result1 is .... 
     str result2 is ....   
    """ 
+0

不適用於我。你需要安裝一些特殊的東西,還是告訴Sphinx它必須使用字段列表? – PatriceG