Python PEP 8 docstring line length

Claudiu picture Claudiu · Mar 15, 2013 · Viewed 7.6k times · Source

I've recently begun figuring it would be a good idea to follow PEP 8. I made my editor display the 80-column mark and am now attempting to wrap lines to fit in it. My question is this. In PEP 8 it says:

Limit all lines to a maximum of 79 characters.

Makes sense.

[...] For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended.

Why 72? Why isn't 79 fine for docstrings or comments?

Answer

Gareth Latty picture Gareth Latty · Mar 15, 2013

I believe it's a hangover from text documents:

At the end of the typewriter age, most designs were geared toward 72 CPL, derived from a pitch of 12 characters per inch, multiplied by 6 inches (see for example IBM Selectric). This would ensure at least 1 inch for each margin, with the U.S. government at the time having standardized on 8 1/2×11" paper.

Source

Many plain text documents still conform to 72 CPL out of tradition.

I think this is just as docstrings are often used in contexts outside of code, so it makes sense to conform to the style most plain text documents use to try and remain as consistent as possible. For example, the text of man pages are generally wrapped to 72 characters. By limiting docstrings to 72 characters, the output of help() mirrors this.

This question on Programmers may also be relevant.