简体   繁体   English

多行加空格 PyCharm

[英]Add spaces to several lines PyCharm

Here is a my problem with a minimal reproducible example:这是我的一个最小可重现示例的问题:

    def additional():
        df_additional_data = pd.read_excel("something.xlsx")
    
        for _, row in df_saga.iterrows():
            req = """
                  UPDATE table_name
                SET column1 = value1, column2 = value2, ...
                WHERE condition;
                  """

I want to add two spaces to both those lines (the one starting with SET and the one starting with WHERE ).我想在这两行中添加两个空格(以SET开头的行和以WHERE开头的行)。 I cannot use TAB because it adds 4 spaces.我不能使用TAB ,因为它会增加 4 个空格。 I cannot use Ctrl Alt I because it's inside """ """ and it doesn't work inside those.我无法使用Ctrl Alt I ,因为它位于“””“””内,并且在其中不起作用。 I know you can do it by hand, but in my case I have over 200 lines in the """ """ string.我知道您可以手动完成,但就我而言,“””“””字符串中有 200 多行。 And I don't want to hire an intern just to add spaces.而且我不想仅仅为了增加空间而雇用一名实习生。

I'm using PyCharm 2021.3.3 (Community Edition)我用的是 PyCharm 2021.3.3(社区版)

Build #PC-213.7172.26, built on March 16, 2022
Runtime version: 11.0.14.1+1-b1751.46 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 11 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 2030M
Cores: 16
Non-Bundled Plugins:
    net.seesharpsoft.intellij.plugins.csv (2.18.2)
    com.chesterccw.excelreader (2021.3.2)
    ru.meanmail.plugin.requirements (2022.3-2021.3)

Since formatters generally try not modifying the contents inside strings too much, this would be tricky in an automated way without seeing the actual code, would be complicated, and would probably have hiccups (IMO).由于格式化程序通常尽量不要过多地修改字符串中的内容,因此在没有看到实际代码的情况下以自动方式进行操作会很棘手,会很复杂,并且可能会出现问题(IMO)。

If the only reason using TAB doesn't solve your answer is because it uses 4 spaces, you can temporarily change it to using 2 spaces To do this you will need to do the following:如果使用 TAB 不能解决您的答案的唯一原因是因为它使用 4 个空格,您可以暂时将其更改为使用 2 个空格为此,您需要执行以下操作:

  1. Settings ->Editor -> Code Style -> Python -> indent -> 2. Settings ->Editor -> Code Style -> Python -> indent -> 2。
  2. Settings ->Editor -> Code Style -> Uncheck Detect and use existing file indents for editing Settings ->Editor -> Code Style ->取消选中Detect and use existing file indents for editing

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM