Python样式指南PEP8 /最佳实践多行注释

问题描述 投票:0回答:1

我使用很多代码模式:

1    class myTest():
2        counter = 0      # use this as general counter
3        name_code = ''   # this is the name encoded using the
4                         # standard as defined in ...
5        category = ''    # category of test

第4行不是PEP8标准。 #应该在第5个位置,它看起来很难看:

3        name_code = ''   # this is the name encoded using the
4        #                  standard as defined in ...

您如何评论这种模式?什么是最佳做法?

python coding-style pep8
1个回答
1
投票

我将其作为docstrings进行处理,因此实际上它们可用于Sphinx等其他工具,并可用于例如生成文档:

class myTest():
    counter = 0
    """use this as general counter"""

    name_code = ''
    """this is the name encoded using the standard as defined in ..."""

    category = ''
    """category of test"""

Docstrings通常是多行字符串,因此可以根据需要扩展为多行。

例如,here's一个类,我已经用文档字符串记录了其属性,从而可以从中自动生成this文档。

© www.soinside.com 2019 - 2024. All rights reserved.