pycodestyle 检查代码规范 我在上面说过 PEP 8 只是官方给出的 Python 编码规范,并没有强制要求大家都遵守,但是又由于大家都在用,所以它也就变成了事实上的 Python 代码风格标准 pip install pep8 规范的名字是 PEP 8 ,这个检查代码风格的命令行工具叫 pep8,这个很容易引起大家的困惑,因此 Python 之父建议将 pep8 重新命名为 pycodestyle ,下面我们来看一下 pycodestyle 的用法。 首先通过 pip 安装一下: pip install pycodestyle 对一个或者多个文件运行 pycodestyle,打印检查报告: ? autopep8 格式化代码 autopep8 能够将 Python 代码自动格式化为 PEP 8 风格,它使用 pycodestyle 工具来决定代码中的哪部分需要被格式化,这能够修复大部分 pycodestyle
此外,欢迎大家通过提交issue来投稿和推荐自己的项目~ 本期为大家推荐GitHub上5个优质的Python项目,它们分别是: •newscatcher•pycodestyle•pywinauto•real-url Newscatcher('blackfaldslife.com') news = get_news('wired.co.uk') headlines = get_headlines('wired.co.uk') pycodestyle Star:4k pycodestyle[3]是根据PEP 8中的样式约定检查Python代码的工具,它具有如下特性, •添加新代码检查很容易•快速跳转到错误位置•轻量化•带有全面的测试套件 安装: pip install pycodestyle pip install --upgrade pycodestyle pip uninstall pycodestyle 使用: 可以直接在命令行调用pycodestyle : https://github.com/PyCQA/pycodestyle [4] pywinauto: https://github.com/pywinauto/pywinauto [5] real-url
为了帮助开发者统一代码风格,Python 社区提出了 PEP8 代码编码风格,它并没有强制要求大家必须遵循,Python 官方同时推出了一个检查代码风格是否符合 PEP8 的工具,名字也叫 pep8,后来被重命名为了 pycodestyle 2, "hello python", 0 ], ] 这是一个不符合 PEP8 的代码段,用 pycodestyle 可检测有哪些地方不符合 PEP8 风格 $ pycodestyle link.py link.py:1: [E401] multiple imports on one line link.py:3: [E302] expected 2 blank lines, found 1 pycodestyle 提示我们有两处地方不符合规范,第一个是单行有多个 import,第二个是类与模块之间需要空两行,这只是一个简单代码示例
pycodestyle。就是原来的pep8,帮你检查代码是否符合PEP8标准。 Flake8:静态检查工具,它包含PyFlakes(静态检查Python代码逻辑错误)、pycodestyle和McCabe(分析Python代码复杂度)三个工具
---- 扩充(配置规范提示和格式化): 命令参考:pip install [--user] xxx 规范化提示:pycodestyle or flake8(旧名字) 代码格式化:yapf or autopep8 VSCode配置参考:(Conda默认安装了pycodestyle) ?
它使用pycodestyle工具来确定代码的哪些部分需要被格式化。Autopep8能够修复大部分pycodestyle检测的格式问题。
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py sudo python3.7 get-pip.py sudo pip3.7 install pycodestyle 设置Python的代码格式化 "python.formatting.provider": "yapf", // 设置Python的代码检查 "python.linting.flake8Path": "pycodestyle -V pip 18.0 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7) ---- sudo pip3.7 install pycodestyle /pycodestyle-2.4.0-py2.py3-none-any.whl (62kB) 100% |████████████████████████████████| 71kB 144kB/s Installing collected packages: pycodestyle Successfully installed pycodestyle-2.4.0 ---- sudo pip3.7
第 1 名 Big Ol规则列表:Flake 8(pyflakes,pycodestyle和mccabe)中每个规则的描述和示例。 Flake8是对pyflakes,pycodestyle和mccabe三个工具的封装。
pip install sphinx pip install jupyter_client pip install qtconsole pip install pyflakes pip install pycodestyle
-aggressive --aggressive <filename> flake8(github) Flake8 is a wrapper around these tools: PyFlakes pycodestyle
第 1 名 Big Ol规则列表:Flake 8(pyflakes,pycodestyle和mccabe)中每个规则的描述和示例。 Flake8是对pyflakes,pycodestyle和mccabe三个工具的封装。
In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting.
In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting.
最好Linters的Python代码如下: pycodestyle是一个根据PEP 8中的某些样式约定来检查Python代码的工具。 使用pip安装pycodestyle: $ pip install pycodestyle 可以使用以下命令终端运行pycodestyle: $ pycodestyle code.py code.py: ,' code.py:6:19: E711 comparison to None should be 'if cond is None:' flake8是一个结合了debugger,pyflakes和pycodestyle
静态本地检测 Flake8包装了Pyflakes、Pycodestyle和McCabe,也可以自定义插件。
BaseException: logger.error(....) finally: os.remove(temp_file) 参考: https://github.com/PyCQA/pycodestyle
它使用pycodestyle实用程序来确定代码的哪些部分需要格式化。autopep8能够修复pycodestyle可以报告的大部分格式问题。安装此软件包后,可能需要单击设置并选择“保存时格式化”选项。
psf/black[4] Stars: 34.2k License: MIT picture Black 是一个 Python 代码格式化工具,它提供了速度、确定性和自由,并且摆脱了 pycodestyle
21.0 paddle2onnx-0.7 paddlehub-2.1.0 paddlenlp-2.0.6 pandas-1.3.0 platformdirs-2.0.2 pre-commit-2.13.0 pycodestyle
autopep8 这个是最早的 python 格式化代码工具,它采用 pycodestyle 来分析代码,然后对于不符合 pep 风格的代码进行修复。