How to fix Python indentation

前端 未结 13 1451
梦毁少年i
梦毁少年i 2020-11-22 08:17

I have some Python code that have inconsistent indentation. There is a lot of mixture of tabs and spaces to make the matter even worse, and even space indentation is not pre

13条回答
  •  独厮守ぢ
    2020-11-22 08:49

    autopep8 -i script.py

    Use autopep8

    autopep8 automagically formats Python code to conform to the PEP 8 nullstyle guide. It uses the pep8 utility to determine what parts of the nullcode needs to be formatted. autopep8 is capable of fixing most of the nullformatting issues that can be reported by pep8.

    pip install autopep8
    autopep8 script.py    # print only
    autopep8 -i script.py # write file
    

提交回复
热议问题