Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pep8

I get this error but however I choose to indent it, I still get it, do you know why?

if len(argmaxcomp) == 1:
    print "The complex with the greatest mean abundance is: {0}"\
    .format(argmaxcomp[0])
like image 845
user132290 Avatar asked Oct 15 '15 11:10

user132290


2 Answers

Generally pep8 suggests you prefer parenthesis over continuation lines.

The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation.

That is:

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

Another option, is to use python 3's print:

from __future__ import print_function

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

Note: print_function may break/require updating the rest of the code... anywhere you've used print.

like image 193
Andy Hayden Avatar answered Nov 15 '22 16:11

Andy Hayden


The problem in this case is that there is no indentation at all and obviously the error occurs in the last line. In case parentheses are not an option just add indentation as below:

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

Any amount of spaces works but I don't know what is preferred.

like image 21
st0ne Avatar answered Nov 15 '22 16:11

st0ne