python Python格式化工具
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1032393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python Formatter Tool
提问by user127555
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.
我想知道是否存在一种 Python 美化工具,例如用于 C 代码的 gnu-indent 命令行工具。当然,缩进不是 Python 中的重点,因为它是程序员的责任,但我希望以完全同质的方式编写我的代码,特别注意操作数之间或分隔符前后和块之间始终相同的空格。
回答by candide
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 ;) ).
我是问这个问题的人。事实上,最接近我需要的工具似乎是PythonTidy(当然,它是一个 Python 程序:Python 最好由他自己提供 ;))。
回答by tom
autopep8 attempts to automate making your code conform to pep8 coding standards
autopep8 尝试自动使您的代码符合 pep8 编码标准
回答by Eyal Levin
You can also try yapf
:
您也可以尝试yapf
:
A formatter for Python files
Python 文件的格式化程序