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?
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.
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.
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.
As mentioned, PEP 8 says to use lower_case_with_underscores for variables, methods and functions.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With