问题
I was wondering if there exists a sort of Python beautifier like the gnu-indent command line tool for C code. Of course indentation is not the point in Python since it is programmer's responsibility but I wish to get my code written in a perfectly homogenous way, taking care particularly of having always identical blank space between operands or after and before separators and between blocks.
回答1:
I am the one who asks the question. In fact, the tool the closest to my needs seems to be PythonTidy (it's a Python program of course : Python is best served by himself ;) ).
回答2:
autopep8 attempts to automate making your code conform to pep8 coding standards
https://pypi.python.org/pypi/autopep8
回答3:
You can also try yapf
:
A formatter for Python files
https://github.com/google/yapf/
回答4:
PyLint has some formatting checks.
回答5:
Have you looked at pindent?
来源:https://stackoverflow.com/questions/1032393/python-formatter-tool