评论代码的正确方法.蟒蛇

Vor*_*Vor 5 python comments

我正在阅读PEP8和stackoverflow的一些问题,但是想知道评论之间的空格:

让我说我有这个代码:

class MyBrowser(QWebPage):
    ''' Settings for the browser.'''

    def __init__(self):
        QWebPage.__init__(self)
        # Specifies whether images are automatically loaded in web pages.
        self.settings().setAttribute(QWebSettings.AutoLoadImages, True)

    def userAgentForUrl(self, url):
        ''' Returns a User Agent that will be seen by the website. '''
        return "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.15 (KHTML, like Gecko) Chrome/24.0.1295.0 Safari/537.15"
Run Code Online (Sandbox Code Playgroud)

在注释和实际代码之间放置空行的最pythonic方法是什么?我想向一些专家展示我的计划.并希望我的代码看起来更专业.

Jas*_*ske 12

我不知道这是否代表"社区标准",但这里是Google的Python风格指南(因为它们与评论有关).特别是班级:

class SampleClass(object):
    """Summary of class here.

    Longer class information....
    Longer class information....

    Attributes:
        likes_spam: A boolean indicating if we like SPAM or not.
        eggs: An integer count of the eggs we have laid.
    """

    def __init__(self, likes_spam=False):
        """Inits SampleClass with blah."""
        self.likes_spam = likes_spam
        self.eggs = 0

    def public_method(self):
        """Performs operation blah."""
Run Code Online (Sandbox Code Playgroud)