打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Python类和方法注释规范

Python类和方法注释规范




注释风格

  1. reStructuredTextPyCharm默认
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文档
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
PyCharm高手技巧篇:会这三招,代码再烂也不怕,拿走不谢
超级详细实用的pycharm常用快捷键介绍 | w3c笔记
最详细的Python安装教程以及Pycharm安装和使用!小学生都能学会
pycharm注释快捷键
在pycharm中显示python画的图方法
怎么下载Python中的模块?Python下载模块的两种方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服