Continuation line under indented for visual indent как исправить
As it stands, using the PEP8 script, it gives me an «E128: continuation line under-indented for visual indent» error on the second line.
I’ve tried a whole bunch of different ways of formatting, and the only way I can get PEP8 to stop complaining is:
But this looks like garbage.
Suggestions? E124, E126, and E128 seem to be a huge pain!
I don’t mind solutions which have the , and context_instance. are at the same indentation level.
I get 'continuation line under-indented for visual indent' error
I get a continuation line under-indented for visual indent error on the code below:
How should this code be formatted to remove the error?
2 Answers 2
This case is covered in PEP-8. In summary, to fix this you need to ensure that when you indent lines that are inside parentheses that you align the next line with the character that is after the opening parenthesis. For example, you should do this when you continue code in parentheses.
You are currently doing it like this.
To fix your indentation you should do it like this.
From Stephen Rauch’s answer you may have noticed that there is a little more to this as well. instead of using slashes to do line continuation you may surround the entire line in parenthesis and then break the lines into strings, python automatically joins adjacent string literals. For example if you had a string and you did this before.
You should do this instead.
This way is a lot more readable and a lot nicer for you to work with. Also do note, there is another PEP-8 approved way to continue parenthesis lines. Instead of doing.
You may also do this.
To do this you must leave the first line blank after the opening parentheses and then you MUST indent in from the current block to start your continuation. I hope this edit furthers your understanding more. If you want to learn more about python style, then just give the PEP guides a quick read through (they are the standard for python code).
Name already in use
Flake8Rules / _rules / E128.md
- Go to file T
- Go to line L
- Copy path
- Copy permalink
- Open with Desktop
- View raw
- Copy raw contents Copy raw contents
Copy raw contents
Copy raw contents
A continuation line is under-indented for a visual indentation.
In this example the string «World» is under-indented by two spaces.
Footer
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
PEP8 E128: не могу понять, почему помечается линия
Я использую Sublime + Anaconda, который имеет встроенную функцию PyLint.
Я не могу понять, почему строка pars_f_name) в следующем блоке:
Я пробовал все отступы, о которых я мог подумать (как предложено здесь), но Anaconda продолжает отмечать эту строку как предупреждение PEP8 E128.
Что я здесь делаю неправильно?
2 ответа
Вам нужно дополнительно отложить аргументы str.format() :
Как личный выбор, я бы поставил эти аргументы на одну строку с отступом:
В основном он жалуется на отсутствие отступов для части str.format() ; но форматирование вашего кода в соответствии с приведенным выше примером делает его более читаемым!
Обновление: Это называется «висячий отступ» в PEP8 (см. ответ @MartijnPieters). Этот ответ больше напоминает «здесь, как его исправить и сделать его читаемым одновременно». (к сожалению, в этом есть много конкурирующих субъективных мнений!)