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 importscommand (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 语法?
基础教程推荐
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
