向多行添加空格 PyCharm

发布于 2025-01-18 05:49:09 字数 1269 浏览 1 评论 0原文

这是我的问题,有一个最小的可重现示例:

    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;
                  """

我想在这两行中添加两个空格(以 SET 开头的一行和以 WHERE 开头的一行)。 我无法使用 TAB 因为它添加了 4 个空格。 我无法使用 Ctrl Alt I 因为它位于“””内“”“并且它在这些内部不起作用。我知道您可以手动完成,但就我而言,“””“””字符串中有 200 多行。我不想雇佣实习生只是为了增加空间。

我使用的是 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)

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).
I cannot use TAB because it adds 4 spaces.
I cannot use Ctrl Alt I because it's inside """ """ and it doesn't work inside those. I know you can do it by hand, but in my case I have over 200 lines in the """ """ string. And I don't want to hire an intern just to add spaces.

I'm using PyCharm 2021.3.3 (Community Edition)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪我们做朋友吧 2025-01-25 05:49:09

由于格式化程序通常不会过多修改字符串内的内容,因此在没有看到实际代码的情况下以自动化方式实现这一点会很棘手,会很复杂,并且可能会出现问题(IMO)。

如果使用 TAB 不能解决您的问题的唯一原因是因为它使用 4 个空格,您可以暂时将其更改为使用 2 个空格为此,您需要执行以下操作:

  1. Settings ->Editor ->代码风格->蟒蛇->缩进 -> 2.
  2. 设置->编辑器->代码风格-> 取消选中检测并使用现有文件缩进进行编辑

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).

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:

  1. Settings ->Editor -> Code Style -> Python -> indent -> 2.
  2. Settings ->Editor -> Code Style -> Uncheck Detect and use existing file indents for editing
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文