开发者

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 f开发者_高级运维or indentation?


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.


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: '    ']


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜