pycodestyle 命令

| 选择喜欢的代码风格  

pycodestyle 命令安装:

-bash/zsh: pycodestyle: command not found

# Windows (WSL2)
sudo apt-get update sudo apt-get install pycodestyle

# Debian
apt-get install pycodestyle

# Ubuntu
apt-get install pycodestyle

# Arch Linux
pacman -S pycodestyle

# Kali Linux
apt-get install pycodestyle

# Fedora
dnf install pycodestyle

# OS X
brew install pycodestyle

# Raspbian
apt-get install pycodestyle

# Dockerfile

pycodestyle 命令补充说明:

pycodestyle 以前称为 pep8 是 Python 社区中广泛使用的工具之一,用于检查 Python 代码是否符合 PEP 8 风格指南的工具。PEP 8 是 Python 社区广泛接受的一种代码风格指南,旨在提高代码的可读性,并促使开发人员采用一致的编码风格。有助于确保代码在风格上保持一致,提高代码的可读性和可维护性。

pycodestyle 命令语法:

pycodestyle [options] input ...

pycodestyle 命令选项:

show program's version number and exit

-h, --help
show this help message and exit

-v, --verbose
print status messages, or debug with -vv

-q, --quiet
report only file names, or nothing with -qq

exclude files or directories which match these comma separated patterns (default: .svn,CVS,.bzr,.hg,.git,__pycache__,.tox)

when parsing directories, only check filenames matching these comma separated patterns (default: *.py)

select errors and warning (e.g. E,W6)

skip errors and warnings (e.g. E4,W) (default: E121,E123,E126,E226,E24,E704,W503)

show first occurrence of each error

-r, --repeat
(obsolete) show all occurrences of the same error

show source code for each error

show text of PEP 8 for each error (implies --first)

count errors and warnings

print total number of errors and warnings to standard error and set exit code to 1 if total is not null

set maximum allowed line length (default: 79)

hang closing bracket instead of matching indentation of opening bracket's line

set the error format [default|pylint|<custom>]

report only lines changed according to the unified diff received on STDIN

measure processing speed

user config file location (default: $HOME/.config/pycodestyle)

pycodestyle 命令实例:

pycodestyle 检查单个文件的样式:


pycodestyle 检查多个 python 文件:


pycodestyle 仅显示第一次出现的错误:

pycodestyle --first

pycodestyle 显示每个错误的源代码:

pycodestyle --show-source

pycodestyle 显示每个错误的特定 PEP 8 文本:

pycodestyle --show-pep8

pycodestyle 命令扩展阅读: