【发布时间】:2020-09-25 16:50:52
【问题描述】:
为有条件地返回某些内容或NoneType 的函数编写文档字符串的约定是什么?我看到使用 Sphinx 可能与此相关的帖子,但我想知道以下代码中格式的约定是什么:
def some_func(input):
"""
Some docstring
Parameters
----------
input : float
Some float
Returns
-------
float
if condition met: the result
NoneType
if condition not met: NoneType
"""
if input > 0.5:
return input*100
else:
return
【问题讨论】:
-
@Tibebes.M 我对 sphinx 或帖子中显示的格式一无所知,所以我想知道我的帖子中写的文档字符串的一般约定是什么。
-
Sphinx (sphinx-doc.org/en/master) 是用于大多数 python 项目的文档工具。它从您的文档字符串生成文档。几种文档字符串样式是可能的,例如谷歌风格 (sphinxcontrib-napoleon.readthedocs.io/en/latest/…)。
-
好吧,我没有意识到这一点。我从未听说过 sphinx,只是使用 spyder 自动生成上述格式的文档字符串。