【问题标题】:Is there a shortcut to merge import statements是否有合并导入语句的快捷方式
【发布时间】:2016-09-21 04:04:16
【问题描述】:

我在 python 文件中有以下导入语句。

from a import b
from a import c

现在,我希望将其合并为一行,例如:

from a import b, c

我尝试了 Pycharm 中的组织导入快捷方式:Ctrl+Shift+O。但是,这并没有达到我上面描述的效果。

在 Pycharm 中是否有其他捷径可以做到这一点?只是好奇。

谢谢!

【问题讨论】:

    标签: pycharm


    【解决方案1】:

    转到File > Settings > Editor > Code Style > Python

    现在在 Python Code Style 的导入选项卡中,选中上面的屏幕截图中显示的 Join "from" imports with the same source 框,

    现在每当您通过运行 Ctrl+Alt+Ocode > Optimize imports 运行 Optimize imports 时,导入语句将根据Style Guide for Python Code进行优化排列

    【讨论】:

    • 这就是我一直在寻找的答案。非常感谢。
    猜你喜欢
    • 2012-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    相关资源
    最近更新 更多