Ross Rogers
Ross Rogers

Reputation: 24228

Similar to ``tabnanny``, how can I check that all the python code is using 4 spaces as an indent?

Similar to tabnanny, is there a utility for python to check if a python file is using 4 spaces for indentation?

Upvotes: 0

Views: 971

Answers (3)

interjay
interjay

Reputation: 110148

Pylint can check this among many other things. Here's a warning it gave me with a test file:

W:  3: Bad indentation. Found 3 spaces, expected 4

It's also possible to make it expect another indent type using this command line option:

--indent-string=<string>
             String used as indentation unit. This is usually "    " 
             (4 spaces) or "\t" (1 tab). [current: '    ']

Upvotes: 4

gurney alex
gurney alex

Reputation: 13645

Pylint (http://www.logilab.org/project/pylint) checks this (and much more).

Other Python code checkers (pep8, pyflakes, pychecker...) may do so too.

Upvotes: 1

Dominic Bou-Samra
Dominic Bou-Samra

Reputation: 15416

You can try the reindent.py script, found in tools/scripts of your python install.

Change Python (.py) files to use 4-space indents and no hard tab characters. Also trim excess spaces and tabs from ends of lines, and remove empty lines at the end of files. Also ensure the last line ends with a newline.

Upvotes: 4

Related Questions