代码之家  ›  专栏  ›  技术社区  ›  Ross Rogers

与“tabnanny”类似,如何检查所有python代码是否使用4个空格作为缩进?

  •  0
  • Ross Rogers  · 技术社区  · 16 年前

    类似 tabnanny

    3 回复  |  直到 16 年前
        1
  •  4
  •   Dominic Bou-Samra    16 年前

    你可以试试reindent.py脚本,可以在python安装的工具/脚本中找到。

    将Python(.py)文件更改为使用4空格缩进,而不使用硬制表符。还要从行尾修剪多余的空格和制表符,并删除文件末尾的空行。还要确保最后一行以换行符结尾。

        2
  •  4
  •   interjay    16 年前

    Pylint 可以在很多其他事情中检查这个。这里有一个警告,它给了我一个测试文件:

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

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

    http://www.logilab.org/project/pylint )检查这个(还有更多)。

    其他Python代码检查器(pep8、pyflakes、pychecker…)也可以这样做。