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
dockerfile.run/pycodestyle

pycodestyle 命令补充说明:


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

pycodestyle 命令语法:


pycodestyle [options] input ...

pycodestyle 命令选项:


--version
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=patterns
exclude files or directories which match these comma separated patterns (default: .svn,CVS,.bzr,.hg,.git,__pycache__,.tox)

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

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

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

--first
show first occurrence of each error

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

--show-source
show source code for each error

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

--statistics
count errors and warnings

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

--max-line-length=n
set maximum allowed line length (default: 79)

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

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

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

--benchmark
measure processing speed

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

pycodestyle 命令实例:


pycodestyle 检查单个文件的样式:

pycodestyle file.py

pycodestyle 检查多个 python 文件:

pycodestyle file1.py file2.py file3.py

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

pycodestyle --first file.py

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

pycodestyle --show-source file.py

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

pycodestyle --show-pep8 file.py

pycodestyle 命令扩展阅读:




发表评论