如何在Python 2中使用reStructuredText记录多个返回值?
他们说“用于Python文档的标记是”。我的问题是:如何编写块注释来显示多个返回值如何在Python 2中使用reStructuredText记录多个返回值?,python,python-2.7,documentation,restructuredtext,Python,Python 2.7,Documentation,Restructuredtext,他们说“用于Python文档的标记是”。我的问题是:如何编写块注释来显示多个返回值 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 reStructur
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文档中发现了一个使用StructuredText的示例,但它没有一个用于记录多个返回值的示例。有关
返回
和rtype
的讨论,但没有涉及多个返回值。正如wwi在评论中提到的,使用的详细格式没有严格定义
对于我自己,我通常使用你上面使用的符号风格。它支持换行,所以只要在你觉得必要的地方换行就行了
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 ....
"""
有一个折衷的解决方案:只需写在正常的降价文本。 e、 g 定义函数(a,b): """ :param int a:第一个输入 :param int a:第二个输入 :返回: -x-第一输出 -y秒输出 """ 返回x,y 这将生成以下文档: 几乎是我们想要的,对吧 这样做的缺点是不能为每个元素指定返回类型。你必须自己写,比如
“”“
:返回:
-x(:py:class:`int`)-第一个输出
"""
似乎任何东西都与docstring相关,只要它在整个项目中清晰、简洁且一致。写一些适合你目的的东西。有一些广泛的惯例。查看您计算机上的Python dot py文件,看看开发人员是如何做到这一点的。例如,它返回了多个内容。对我来说不起作用。您是否必须安装一些特殊的东西,或者告诉Sphinx它必须使用字段列表?