yapf是一個Python文件代碼格式化工具,經過 YAPF 優化後,代碼風格可統一,在每次代碼審查中,也就沒有必要爭論風格了。less
usage: yapf [-h] [-v] [-d | -i] [-r | -l START-END] [-e PATTERN] [--style STYLE] [--style-help] [--no-local-style] [--verify] [files [files ...]] Formatter for Python code. positional arguments: files optional arguments: -h, --help show this help message and exit -v, --version show version number and exit -d, --diff print the diff for the fixed source -i, --in-place make changes to files in place -r, --recursive run recursively over directories -l START-END, --lines START-END range of lines to reformat, one-based -e PATTERN, --exclude PATTERN patterns for files to exclude from formatting --style STYLE specify formatting style: either a style name (for example "pep8" or "google"), or the name of a file with style settings. The default is pep8 unless a .style.yapf or setup.cfg file located in one of the parent directories of the source file (or current directory for stdin) --style-help show style settings and exit --no-local-style don't search for local style definition --verify try to verify reformatted code for syntax errors
yapf -d hello.py
yapf -i hello.py