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:

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:

<span>[tool.black]</span>
<span>line-length</span> <span>=</span> <span>119</span>
<span>[tool.black]</span>
<span>line-length</span> <span>=</span> <span>119</span>
[tool.black] line-length = 119

Enter fullscreen mode Exit fullscreen mode


Was this helpful? Did I save you some time?

🫖 Buy Me A Tea! ️


原文链接:VSCode: Setting line lengths in the Black Python code formatter

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
Worrying does not empty tomorrow of its troubles, it empties today of its strength.
担忧不会清空明日的烦恼,它只会丧失今日的勇气
评论 抢沙发

请登录后发表评论

    暂无评论内容