tags:

views:

90

answers:

3

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

+4  A: 

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: '    ']
interjay
+4  A: 

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.

Dominic Bou-Samra
+1  A: 

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

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

gurney alex