← 返回命令列表

Linux command

pycodestyle 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Check Python file

pycodestyle [script.py]

Check directory

pycodestyle [src/]

Show source code

pycodestyle --show-source [script.py]

Show PEP8 text

pycodestyle --show-pep8 [script.py]

Ignore specific errors

pycodestyle --ignore=[E501,W503] [script.py]

Select specific errors only

pycodestyle --select=[E1,W1] [script.py]

Set max line length

pycodestyle --max-line-length=[120] [script.py]

Show statistics

pycodestyle --statistics [src/]

说明

pycodestyle (formerly pep8) checks Python code against PEP 8 style guidelines. It identifies formatting issues without modifying code. PEP 8 defines Python's official style: indentation, spacing, naming, and line length conventions. Consistent style improves readability. Error codes group related issues. E5 codes relate to line length. W503/W504 handle line breaks in expressions. Specific codes can be ignored. Configuration files (setup.cfg, tox.ini, .pycodestyle) define project-wide settings. These override command-line defaults. The tool doesn't fix issues automatically. Use autopep8 or black for automatic formatting. Integration with editors shows issues in real-time. CI pipelines catch style violations before merge.

参数

--ignore _CODES_
Skip error codes.
--select _CODES_
Show only error codes.
--max-line-length _N_
Line length limit (default 79).
--show-source
Show source code.
--show-pep8
Show PEP8 documentation.
--statistics
Show error statistics.
--count
Print total errors.
--config _FILE_
Configuration file.
--first
Show first error only.
-q, --quiet
Quiet mode.
--benchmark
Time the run.

FAQ

What is the pycodestyle command used for?

pycodestyle (formerly pep8) checks Python code against PEP 8 style guidelines. It identifies formatting issues without modifying code. PEP 8 defines Python's official style: indentation, spacing, naming, and line length conventions. Consistent style improves readability. Error codes group related issues. E5 codes relate to line length. W503/W504 handle line breaks in expressions. Specific codes can be ignored. Configuration files (setup.cfg, tox.ini, .pycodestyle) define project-wide settings. These override command-line defaults. The tool doesn't fix issues automatically. Use autopep8 or black for automatic formatting. Integration with editors shows issues in real-time. CI pipelines catch style violations before merge.

How do I run a basic pycodestyle example?

Run `pycodestyle [script.py]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --ignore _CODES_ do in pycodestyle?

Skip error codes.