Search code examples
pythonpep8

How to break a line in a function definition in Python according to pep8?


I have the following line of code that is just over the limit of 79 characters:

def ReportResults(self, intTestID, startTime, stopTime, version, serverType):

How do I break the line in the correct way according to pep8?


Solution

  • According to PEP8:

    The Python standard library is conservative and requires limiting lines to 79 characters (and docstrings/comments to 72).

    This is in my opinion the main rule to observe.

    Besides this rule, PEP8 recommends aligning brackets, so I would do something like this:

    def report_results(self,
                       intTestID,
                       startTime,
                       stopTime,
                       version,
                       serverType):
        pass
    

    Note that I renamed your method report_results, following the recommended lower_case_with_underscores. Also, notice that the indentation should be aligned with the first letter of the first parameter and not the parenthesis.