gpt4 book ai didi

python - 程序化 python 源格式化程序

转载 作者:IT老高 更新时间:2023-10-28 21:04:33 25 4
gpt4 key购买 nike

我有大量的 Python 代码,需要对其施加符合 pep8 的样式/格式。 pep8 有各种规则的变体(如 this one by a coworker ),但最难的是处理分割太长的行和格式化修改后的代码。

我已经查看了关于此的问题:

  1. python-formatter-tool
  2. python-source-formatter-pretty-printer

它们来自 2009 年和 2010 年。我希望从那时起开发出更好的工具。

我知道 PythonTidy 非常好,但会使很多代码变得更糟,恕我直言。 Pylint 检测格式错误但不纠正它们。 Web 服务与我的要求并不真正相关,因为我想要一个可以作为构建一部分的工具。

是否有人提出了尚未涵盖的建议?谢谢。

最佳答案

另一个看起来不错的:autopep8

但请注意,盲目遵循 PEP8 中的所有约定并不真正符合 PEP8 的精神。来自 PEP8 本身:

But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply.

关于python - 程序化 python 源格式化程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9242748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com