PChao
PChao

Reputation: 439

how to fix the "W293 blank line contains whitespace"

my python code produce the following warning message:

(1) \dir\file.py:8:1 W293 blank lines contains whitespace
this comes after commands[0] flake8 XXX

how do you fix the issue?

Upvotes: 10

Views: 24366

Answers (3)

Niko Fohr
Niko Fohr

Reputation: 33770

While in most cases it is best to just remove the extra whitespace from the lines, sometimes it is not possible. For example, when working with multiline strings where white space has some semantic meaning. Then, the best you can do is to add # noqa: W293 to the line which ends the string. For example:

my_long_txt = """
  For some reason
       
  whitespace required on empty line above
"""  # noqa: W293

This tells linters to skip linting the entire string for the W293.

Upvotes: 1

Mister Brainley
Mister Brainley

Reputation: 662

Using the same principal from this question, you can use autopep8 to automatically fix these. The syntax is ...

    autopep8 --select=W293 --in-place your_file.py

Upvotes: 17

jgritty
jgritty

Reputation: 11915

Simply delete the spaces, tabs, or other white space characters from line 8 in file.py.

Upvotes: 5

Related Questions