Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 667
Hafiz Hilman Mohammad Sofian Avatar asked Dec 24 '22 11:12

Hafiz Hilman Mohammad Sofian


1 Answers

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.

like image 81
ConnectedSystems Avatar answered May 16 '23 10:05

ConnectedSystems