geekdoc-python-zh/docs/pythoncentral/using-yapf-yet-another-pyth...

15 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用 YAPF(另一种 Python 格式化程序)
> 原文:<https://www.pythoncentral.io/using-yapf-yet-another-python-formatter/>
另一个 Python 格式化程序 (YAPF)是编写 Python 的一个有价值的工具。YAPF 是一个开源的 Python 格式化程序,它使编写干净的 Python 代码变得容易得多,所以你可以花更多的时间编写代码,而不用担心代码看起来怎么样。使用这个格式化程序的一个很大的优点(除了漂亮的代码之外)是,它使得由任意数量的开发人员编写的 Python 代码集成到一个文件甚至一个大的目录或项目中变得非常容易。
正如你将在他们的 github 页面上看到的YAPF 会拿走你丑陋的代码:
[![screen-shot-2016-10-31-at-1-20-35-pm](img/417d8827a593f38ef8f4c514e05032d2.png)](https://www.pythoncentral.io/wp-content/uploads/2016/11/Screen-Shot-2016-10-31-at-1.20.35-PM.png)
并将其重新格式化成组织良好的代码:
[![screen-shot-2016-10-31-at-1-20-40-pm](img/d4cfa92cd1757a4345317c6d2034e36a.png)](https://www.pythoncentral.io/wp-content/uploads/2016/11/Screen-Shot-2016-10-31-at-1.20.40-PM.png)
YAPF 不是一般的重新格式化程序,因为它会重新格式化你的整个文件,而不仅仅是把你的代码一行一行地格式化成一个好看的模板。它实际上重新组织和重构了您的 Python不仅仅是为了让它看起来更好而是为了帮助优化性能。如果你写了很多 Python它确实是你可以使用的不可或缺的工具。