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 语法?


基础教程推荐
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01