VSCode: Setting line lengths in the Black Python code formatter

adamlombard

Adam Lombard

Posted on May 1, 2020

VSCode: Setting line lengths in the Black Python code formatter

The docs for the Black Python code formatter say that the formatter "is not configurable". This is largely true, but if you have Black set up to work in VSCode, you can configure the line length.

In VSCode, go 'Code -> Preferences -> Settings' and search for "python formatting black args".

Add two separate arguments, in this order: --line-length and n, where "n" is your desired number of allowed characters per line:

Interface for adding Black formatting arguments in VSCode

A few notes about line lengths in Python:


If you are working on a shared project with a team, consider bypassing the VSCode settings entirely, and setting line lengths via the project's pyproject.toml:



[tool.black]
line-length = 119


Enter fullscreen mode Exit fullscreen mode

Was this helpful? Did I save you some time?

🫖 Buy Me A Tea! ☕️


💖 💪 🙅 🚩
adamlombard
Adam Lombard

Posted on May 1, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related