Python, PEP-8, E122 line continuation missing indentation or outdented

I get this error, but, nevertheless, I prefer its indentation, I still get it, you know why?

if len(argmaxcomp) == 1:
    print "The complex with the greatest mean abundance is: {0}"\
    .format(argmaxcomp[0])
+4
source share
5 answers

Typically, pep8 suggests you prefer parentheses over continuation lines .

The preferred way to wrap long strings is to use line continuation under Python in parentheses, brackets, and curly braces. Long lines can be split into multiple lines, wrapping expressions in parentheses. They should be used instead of using a backslash to continue the line.

I.e:

if len(argmaxcomp) == 1:
    print("The complex with the greatest mean abundance is: {0}"
          .format(argmaxcomp[0]))

Another option is to use python 3 print:

from __future__ import print_function

if len(argmaxcomp) == 1:
    print("The complex with the greatest mean abundance is:", argmaxcomp[0])

. print_function / ... , .

+4

PEP8, :

Python , . , . .

- . , long, multiple -statements ,

( PEP8-E122), paranthesis , () :

if len(argmaxcomp) == 1:
    print("The complex with the greatest mean abundance is: {0}"
          .format(argmaxcomp[0]))
#         ^--------- The bracket opens here

2 , , ( ):

  • - with
  • assert s

, ( python2), , :

if len(argmaxcomp) == 1:
    print "The complex with the greatest mean abundance is: {0}" \
          .format(argmaxcomp[0])
#         ^--------- The first expression starts here
0

, , , . , , :

if len(argmaxcomp) == 1:
    print "The complex with the greatest mean abundance is: {0}" \
        .format(argmaxcomp[0])

, , .

0
source

I did not get the above error, but I tried the types below, Please post with the error so that we can check

In [6]: argmaxcomp = [100]

In [7]: if len(argmaxcomp) == 1:
   ...:     print 'val: {0}'\
   ...:     .format(argmaxcomp[0])
   ...:     
val: 100

In [8]: if len(argmaxcomp) == 1:
   ...:     print 'val: {0}'.format(argmaxcomp[0])
   ...:     
val: 100

In [9]: if len(argmaxcomp) == 1:
   ...:     print 'val: {0}'.format(
   ...:     argmaxcomp[0])
   ...:     
val: 100
0
source

We had a similar problem and it was resolved. I think the problem with the OP code is that there may be a space between the continuation lines. There should be nothing but \ n.

0
source

Source: https://habr.com/ru/post/1611776/


All Articles