Hafiz Hilman Mohammad Sofian Hafiz Hilman Mohammad Sofian - 4 years ago 161
Python Question

What does it means to not exceeding 80 characters in a line in Python?

There is a mention that it is preferable for that a line in a Python script should not exceed more than 80 characters. For example:

print("A very long strings")


Does it include the characters of the
print
function, the strings (including spaces), parenthesis etc.?

And does it not limited to other functions besides
print
?

What is the reason behind this? Already googled for answers but still can't really get the picture.

Answer Source

It includes everything on the line.

The reasoning is that very long lines hinder clarity and readability.

To use an example from the python code style guide which is easier for you to read?

with open('/path/to/some/file/you/want/to/read') as file_1, open('/path/to/some/file/being/written', 'w') as file_2:
    file_2.write(file_1.read())

or

with open('/path/to/some/file/you/want/to/read') as file_1, \
     open('/path/to/some/file/being/written', 'w') as file_2:
         file_2.write(file_1.read())

One other reason is historical. The style guide in the same section I link to above mentions a 72, 79, and 80-100 character limit for various situations. These are the column lengths of a punch card.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download