Python: Auto Format Code
the 2 best python auto formatters are
yapfis written in python, algorithm based on clang-format. code owned by google and written by Bill Wendling (aka gwelymernans, email@example.com) [https://github.com/gwelymernans].
blackis written in python by Łukasz Langa [https://lukasz.langa.pl/], a Python Core Dev.
yapfsupport various styles. pep8, google, facebook, with many tweakings.
blackis just one style.
yapfrepo is 937k
blackrepo is 5,431k
blackdoes not support Python 2 since version 22.0 (released 2022 Jan).
pip install yapf pip install black
# print help yapf -h # print diff yapf -d filename.py # change file in-place yapf -i filename.py # pep8 style yapf -i filename.py # google style yapf -i --style google filename.py # print style help yapf --style-help
# print help black -h # print diff black -diff filename.py # change file in-place black filename.py # take input from stdin black - -q