栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python类和方法注释规范

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python类和方法注释规范

Python类和方法注释规范




注释风格
  1. reStructuredText(PyCharm默认)
def func(path, field_storage, temporary):
    '''基本描述

    详细描述

    :param path: The path of the file to wrap
    :type path: str
    :param field_storage: The :class:`FileStorage` instance to wrap
    :type field_storage: FileStorage
    :param temporary: Whether or not to delete the file when the File instance is destructed
    :type temporary: bool
    :returns: A buffered writable file descriptor
    :rtype: BufferedFileStorage
    '''
    pass
  1. NumPy
def func(path, field_storage, temporary):
    '''基本描述

    详细描述

    Parameters
    ----------
    path : str
        The path of the file to wrap
    field_storage : FileStorage
        The :class:`FileStorage` instance to wrap
    temporary : bool
        Whether or not to delete the file when the File instance is destructed

    Returns
    -------
    BufferedFileStorage
        A buffered writable file descriptor
    '''
    pass
  1. Google(官方推荐)
def func(path, field_storage, temporary):
    '''基本描述

    详细描述

    Args:
        path (str): The path of the file to wrap
        field_storage (FileStorage): The :class:`FileStorage` instance to wrap
        temporary (bool): Whether or not to delete the file when the File instance is destructed

    Returns:
        BufferedFileStorage: A buffered writable file descriptor
    '''
    pass
风格特点适用
reStructuredText用冒号分隔PyCharm默认
NumPy用下划线分隔倾向垂直,长而深的文档
Google用缩进分隔倾向水平,短而简单的文档

Sphinx对NumPy和Google风格的对比,英文不好可以参考中文版



小技巧

在PyCharm中Ctrl+Q可快速查看注释



参考文献
  1. Python风格规范 — Google 开源项目风格指南
  2. Sphinx入门——快速生成Python文档
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/833748.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号