小编mas*_*oud的帖子

如何在Python中为返回None但在磁盘中写入文件的函数编写文档字符串?

我想使用 Python 文档字符串来更好地记录我的代码。

在下面的函数中,它将一个列表作为输入并将文件写入磁盘。我想知道如何将文档字符串中函数的输出记录为 None 中的函数返回类型。它有约定吗?

def foo(list_of_items: list) -> None :
    """Simple function.

    Parameters
    ----------
        list_of_items : list of str
        list of some texts    

    Returns
    -------
        what is the best way to write this section?
    """

    file = open('/path/output.txt')
    file.write(list_of_items[1])
    file.close()
Run Code Online (Sandbox Code Playgroud)

python docstring

5
推荐指数
1
解决办法
3558
查看次数

标签 统计

docstring ×1

python ×1