Is there an IDE/utility to refactor Python * imports to use standard module.member syntax?(是否有 IDE/实用程序来重构 Python * 导入以使用标准 module.member 语法?)
问题描述
我最近的任务是维护大量使用 from module import *
的代码.
I was recently tasked with maintaining a bunch of code that uses from module import *
fairly heavily.
这个代码库已经变得足够大,以至于导入冲突/命名模糊/这个函数到底是从哪里来的,大约有八个导入的模块有一个同名?!"主义变得越来越普遍.
This codebase has gotten big enough that import conflicts/naming ambiguity/"where the heck did this function come from, there are like eight imported modules that have one with the same name?!"ism have become more and more common.
展望未来,我一直在使用显式成员(即 import module ... module.object.function()
以使我所做的维护工作更具可读性.
Moving forward, I've been using explicit members (i.e. import module ... module.object.function()
to make the maintenance work I do more readable.
但我想知道:是否有一个 IDE 或实用程序可以稳健地解析 Python 代码并将 * import 语句重构为模块 import 语句,然后将完整的模块路径添加到对该模块成员的所有引用?强>
我们没有大量使用元编程/反射/inspect
/monkeypatching,所以如果上述 IDE/util 在这些事情上表现不佳,那没关系.
We're not using metaprogramming/reflection/inspect
/monkeypatching heavily, so if aforementened IDE/util behaves poorly with such things, that is OK.
推荐答案
不是一个完美的解决方案,但我通常会这样做:
Not a perfect solution, but what I usually do is this:
- 打开 Pydev
- 删除所有
*
导入 - 使用
optimize imports
命令 (ctrl+shift+o
) 重新添加所有导入
- Open Pydev
- Remove all
*
imports - Use the
optimize imports
command (ctrl+shift+o
) to re-add all the imports
大致解决了问题:)
如果您想自己构建解决方案,请尝试 http://docs.python.org/库/modulefinder.html
If you want to build a solution yourself, try http://docs.python.org/library/modulefinder.html
这篇关于是否有 IDE/实用程序来重构 Python * 导入以使用标准 module.member 语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否有 IDE/实用程序来重构 Python * 导入以使用标准 module.member 语法?


基础教程推荐
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01