简体   繁体   English

黑色格式化程序 - Python

[英]The Black Formatter - Python

I just started using the Black Formatter module with VSCode everything was going well till I just noticed that it uses double quotes over single quotes which I already was using in my code.. and it overrode that..我刚开始将 Black Formatter 模块与 VSCode 一起使用,一切进展顺利,直到我注意到它使用双引号而不是我已经在我的代码中使用的单引号..它覆盖了..

So, is there an Black Argument that I could add to VSCode which solves this problem?那么,有没有我可以添加到 VSCode 中的 Black Argument 来解决这个问题?

Thanks.谢谢。

I don't know how it works for you all of that:我不知道它是如何为你工作的:

 {
    ...
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
        "--skip-string-normalization"
    ]
    ...
}

or或者

{
    ...

    "python.formatting.blackArgs": [
        "-S"
    ],
    ...
}

I've tried everything and THE ONLY works for me is:我已经尝试了一切,唯一对我有用的是:

"black-formatter.args": ["-S"]

And VSCode for some reason installed via pip install -U black , don't know it is crucial or not.和 VSCode 由于某种原因通过pip install -U black ,不知道它是否重要。

You can use the --skip-string-normalization option at the command line, or in your VSCode options.您可以在命令行或 VSCode 选项中使用--skip-string-normalization选项。

See here: https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#strings请参阅此处: https : //black.readthedocs.io/en/stable/the_black_code_style/current_style.html#strings

For example:例如:

{
    ...
    "python.formatting.provider": "black",
    "python.formatting.blackArgs": [
        "--skip-string-normalization",
        "--line-length",
        "100"
    ]
    ...
}

Good luck!祝你好运!

--skip-string-normalization or -S for short --skip-string-normalization-S简称

{
    ...

    "python.formatting.blackArgs": [
        "-S"
    ],
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 python 中,如果可能,如何调整黑色格式化程序? - In python, how to tweak Black formatter, if possible? 让 Black Python 代码格式化程序对齐注释 - Getting Black Python code formatter to align comments VS Code Python + 黑色格式化程序参数 - python.formatting.blackArgs - VS Code Python + Black formatter arguments - python.formatting.blackArgs 为什么不需要加载 Python 格式化程序(黑色)和 linter(pylint)和 vs 代码? - Why no need to load Python formatter (black) and linter (pylint) and vs code? python black formatter 可以使用制表符而不是空格吗? - Can python black formatter use tabulators instead of spaces? 使用黑色格式化程序在 Python 中的多行 SQL 语句格式化 - Multi-line SQL statement formatting in Python using black formatter poetry管理的python>=3.5项目下如何使用python black formatter? - How to use python black formatter under a project for python>=3.5 managed by poetry? python中的formatter - formatter in python Python 黑色格式化程序与 VSCode 中的规则 flake8 W503 冲突 - Python black formatter conflict with rule flake8 W503 in VSCode 即使在将 Black 配置为格式化程序后,获取“扩展 'Python Language Basics' 无法格式化 ~'/'” - Getting “Extension 'Python Language Basics' cannot format ~'/'” even after configuring Black as formatter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM