[Tutor] Correct style of line break when chaining methods

boB Stepp robertvstepp at gmail.com
Sat Jul 10 12:33:46 EDT 2021


On Sat, Jul 10, 2021 at 11:20 AM boB Stepp <robertvstepp at gmail.com> wrote:
>
> On Sat, Jul 10, 2021 at 11:03 AM Manprit Singh
> <manpritsinghece at gmail.com> wrote:
> >
> > Dear sir,
> >
> > See in this particular example, the length of the line is 75 characters ,
> > and according to PEP 8, in Python a line must not exceed 69 characters.
>
> Are you sure you did not misread the max recommended line length?
>
> https://www.python.org/dev/peps/pep-0008/#id19 says:
>
> <quote>
> Maximum Line Length
>
> Limit all lines to a maximum of 79 characters.
> </quote>
>
> There are some qualifications later for comments and docstrings, but
> these don't apply to your example.

Some further thoughts about this reflecting guidance I've read on
Tutor and elsewhere.

The concept of 80 characters line length is a historical artifact from
the early punch card and terminal days.  However, 80 characters is
often cited as "about" the right line length for humans to process
chunks of information.  But modern software and monitors can
substantially stretch this "about" line length to just about any
length you find comprehensible and convenient.  And remember PEP 8 is
a guideline only.

I am currently using an automatic Python code formatter called
"black".  It determines its default line length a bit longer than
79/80 characters (from
https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length):

<quote>

Line length

You probably noticed the peculiar default line length. Black defaults
to 88 characters per line, which happens to be 10% over 80. This
number was found to produce significantly shorter files than sticking
with 80 (the most popular), or even 79 (used by the standard library).
In general, 90-ish seems like the wise choice.
</quote>

And Mats suggested the need for judgement when you are "close to"
whatever your predetermined line length is.  Splitting lines
unnecessarily can make the code harder to read than fudging your line
length limit sometimes.

boB Stepp


More information about the Tutor mailing list