Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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?

like image 628
Michael Avatar asked Nov 11 '16 07:11

Michael


People also ask

How do I make a line break in Python?

In Python, the new line character “\n” is used to create a new line. When inserted in a string all the characters after the character are added to a new line. Essentially the occurrence of the “\n” indicates that the line ends here and the remaining characters would be displayed in a new line.

How do you break a line in an if statement in Python?

You cannot split a statement into multiple lines in Python by pressing Enter . Instead, use the backslash ( \ ) to indicate that a statement is continued on the next line.

What is PEP8 in Python with example?

PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code.

Which of the following styles does PEP8 recommend for multi word variable names?

As mentioned, PEP 8 says to use lower_case_with_underscores for variables, methods and functions.


1 Answers

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:

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

Note that I renamed your method report_results, following the recommended lower_case_with_underscores.

like image 122
Right leg Avatar answered Oct 01 '22 04:10

Right leg