是否有IDE /实用程序来重构Python *导入以使用标准的module.member语法? [英] Is there an IDE/utility to refactor Python * imports to use standard module.member syntax?

查看:130
本文介绍了是否有IDE /实用程序来重构Python *导入以使用标准的module.member语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近负责维护大量使用来自模块导入* 的代码。

I was recently tasked with maintaining a bunch of code that uses from module import * fairly heavily.

这个代码库变得足够大,以至于导入冲突/命名歧义/这个功能来自何处,有八个导入的模块,其中一个具有相同的名字?!ism变得越来越普遍。

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.

继续前进,我一直在使用显式成员(即导入模块... 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语句到模块导入语句,然后将完整的模块路径预先添加到该模块成员的所有引用?

我们没有使用元编程/反射/ 检查 / 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:


  1. 打开Pydev

  2. 删除所有 * 进口

  3. 使用优化进口命令( ctrl + shift + o )重新添加所有导入

  1. Open Pydev
  2. Remove all * imports
  3. Use the optimize imports command (ctrl+shift+o) to re-add all the imports

大致解决了这个问题: )

Roughly solves the problem :)

如果您想自己构建解决方案,请尝试 http://docs.python.org/library/modulefinder.html

If you want to build a solution yourself, try http://docs.python.org/library/modulefinder.html

这篇关于是否有IDE /实用程序来重构Python *导入以使用标准的module.member语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆