PyCharm - Optimizing Imports (优化导入)

1. Introduction

Sooner or later, some of the imported classes or packages become redundant to the code.
迟早,一些导入的 classes or packages 对代码来说是多余的。

Typically, you have to stop what you are doing, scroll to the head of the file, find the unused imports, and remove them. It is rather easy to forget to remove imports when you remove usages.
通常,您必须停止正在执行的操作,滚动到文件的开头,找到未使用的导入,然后将其删除。很容易忘记删除导入。

PyCharm provides the Optimize Imports feature, which enables you, whenever it is convenient, to remove unused imports from your current file, or from all files in the current directory at once. This helps you avoid unused, excessive and duplicating imports in your project.
PyCharm 提供了优化导入功能,该功能使您可以在方便时随时从当前文件或当前目录中的所有文件中删除未使用的导入。这可以帮助您避免项目中未使用,过多和重复的导入。

excessive [ɪk'sesɪv]:adj. 过分的,过度的

One can remove unused import statements in the entire project or in the current file only.
可以删除整个项目或仅当前文件中未使用的导入语句。

Besides cleaning the code from the unused imports, PyCharm formats the existing import statements according to the Style Guide for Python Code. So doing, PyCharm splits import statements into separate lines, and sorts them into groups (refer to the Imports section for details).
除了清除未使用的导入中的代码外,PyCharm 还根据 《Python 代码样式指南》 格式化现有的导入语句。这样,PyCharm 会将 import 语句拆分为单独的行,并将其分类为组 (refer to the Imports section for details)。

scroll [skroʊl]:v. 滚动,滚屏 n. 卷轴,(石刻或木雕的) 涡卷形装饰
alphabetically [ˌælfəˈbetɪkli]:adv. 照字母顺序排列地

在 Pycharm 编辑环境中冗余的 imports 语句都是灰色显示的。

Also, imports are sorted alphabetically within the respective groups:
导入在各个组中按字母顺序排序:

2. Optimizing imports in project

To optimize imports in the entire project, follow these steps:

  1. Place the caret at the Project tool window and do one of the following:

    • On the main menu, choose Code | Optimize Imports.
    • Press Ctrl+Alt+O.
    • The Optimize Imports dialog box opens.
  2. If your project is under version control, the option Only VCS changed files is enabled. Select or clear this option as required. (如果你的项目受版本控制,则启用 Only VCS changed files 选项。根据需要选择或清除此选项。)
  3. Click Run.

3. Optimizing imports in the current file

To optimize imports in the currently opened file, do one of the following:

  • On the main menu, choose Code | Optimize Imports.
  • Press Ctrl+Alt+O.
  • Place the caret at the import statements and press Alt+Enter, or just click to show the list of suggested intention actions, and then choose Optimize imports.
caret [ˈkærət]:n. 脱字符号,插入符号
dialog ['daɪəlɒɡ]:n. 对话,会话
intention [ɪnˈtenʃn]:n. 意图,目的,意向,愈合

References

https://yongqiang.blog.csdn.net/

PyCharm - Optimizing Imports (优化导入)相关推荐

  1. intelliJ IDEA自动优化导入包

    Settings→Editor→General→Auto Import 选中Optimize imports on the fly和Add unambiguous imports on the fly ...

  2. pycharm 同一个目录下导入py文件时,模块下方出现红色波浪线时如何解决

    此解决方案来自于:https://www.cnblogs.com/my-blogs-for-everone/articles/12270938.html 问题如下: pycharm 同一个目录下导入p ...

  3. Pycharm自定义包的导入

    https://blog.csdn.net/haiyanggeng/article/details/79215819  https://blog.csdn.net/u010278162/article ...

  4. python封装举例_Python+Pycharm—学习1—封装导入

    一.封装 目的: 写了一个复杂功能的实现,下次有相同的需求时可以直接导入这个包来使用.就可以达到复用的目的了.通俗的来讲就是打包.(以下用四则运算举例) 方案: 1.1.新建python工程,新建一个 ...

  5. python包装好后在pycharm IED中无法导入

    Python在终端通过pip安装好包以后,在Pycharm中依然无法使用的解决办法 2018年05月31日 23:00:07 yue_xingyu 阅读数:13428 版权声明: https://bl ...

  6. 条码打印软件之优化导入PDF文档的清晰度

    在条码打印软件旧版中,用过的小伙伴可能会发现,导入PDF文档后,特别是较大的PDF文档, PDF文档在软件中显示有时会出现模糊的情况,而且在连接打印机打印的时候由于色彩之间的转换,可能会出现颜色偏差的 ...

  7. python caffe框架_ubuntu14.04 intel集成显卡配置caffe框架(用cpu跑)+pycharm自带python导入caffe框架...

    用cpu跑,不用安装CUDA. 1.安装依赖库 安装[build-essentials] 安装开发所需要的一些基本的包, sudo apt-get install build-essential BL ...

  8. 最新PyCharm基本使用(3)------编码(Code)、重构(Refactor)

    目录 六.PyCharm中代码的填充.补充.检查.分析.清理等操作 七.PyCharm中的重命名.更改签名.提取.引入.内联(复原).安全删除.调整.转换等重构操作 六.PyCharm中代码的填充.补 ...

  9. IntelliJ IDEA详细配置

    2019独角兽企业重金招聘Python工程师标准>>> IntelliJ IDEA详细配置 关闭Intellij IDEA自动更新 在File->Settings->Ap ...

最新文章

  1. java进入编程界面_java – 编程到界面是什么意思?
  2. C/C++指针与内存管理
  3. 博图编写温度程序_NTC测量温度的两个不同的数值转换程序,你会选择哪一个
  4. 如何使用Python制作一个会动的地球仪?
  5. mysql 8重置root密码_如何在MySQL 8中重置root密码
  6. 《深入实践Spring Boot》一3.3 使用Thymeleaf模板
  7. Oracle 和Mysql Group by的细节与坑
  8. OpenShift 4 之Istio-Tutorial (9) 访问限流
  9. 【SVM分类】基于改进鲸鱼算法优化最小二乘支持向量机实现数据分类matlab代码
  10. Rose与PowerDesigner:两款UML建模工具的对比
  11. ubuntu20.04离线安装rabbitvcs
  12. Word论文参考文献排版
  13. E680手机上能用的 MPlayer
  14. WhatsApp创始人:从领救济到身价68亿
  15. 华为手机刷微博体验更好?技术角度的分析和思考
  16. vue elementui checkbox第一次点击选不中的问题
  17. 省级交通运输行政执法综合管理信息系统工程方案
  18. 网盘直链下载 windows 和 mac 都能使用 (油猴+FMD+直链脚本)
  19. STM8L052C6 低功耗+LCD显示 经验分享
  20. linux备份当前目录压缩,Linux备份压缩命令:tar详解

热门文章

  1. 识别二维码、并保存二维码链接至csv文件
  2. Java实用工具类五:URL转码、解码类
  3. IDEA 如何查看 class 文件反编译后的内容
  4. java正则验证大陆以及港澳台手机号码
  5. python 求解包含两个未知数的方程
  6. 【signal】傅里叶分析和FFT蝶形算法
  7. MSN 登陆不了的解决方法
  8. 【OpenGL ES】OpenGL ES简介
  9. 绝对布局absoluteLayout
  10. 绝对布局AbsoluteLayout学习笔记