← 返回命令列表

Linux command

black 命令

网络

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

常用示例

Format

black [script.py]

Example

black [src/]

Check

black --check [script.py]

Diff

black --diff [script.py]

Example

black -l [100] [script.py]

说明

black is an opinionated Python code formatter. It enforces a consistent style by reformatting code automatically with minimal configuration. Black's approach is to eliminate debate about formatting by providing one correct way. The tool integrates with editors and CI pipelines to ensure consistent Python code style.

参数

--check
Check if files would be reformatted (exit 1 if yes)
--diff
Show diff instead of rewriting
-l, --line-length _n_
Line length (default: 88)
--target-version _py_
Python version (py37, py38, py39, etc.)
--exclude _pattern_
Files/directories to exclude
--include _pattern_
Files/directories to include
--quiet
Minimal output
--verbose
Verbose output
--color/--no-color
Colored output

FAQ

What is the black command used for?

black is an opinionated Python code formatter. It enforces a consistent style by reformatting code automatically with minimal configuration. Black's approach is to eliminate debate about formatting by providing one correct way. The tool integrates with editors and CI pipelines to ensure consistent Python code style.

How do I run a basic black example?

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

What does --check do in black?

Check if files would be reformatted (exit 1 if yes)