自动生成导入,以将一种方法与模块分开

发布于 2024-12-17 11:34:20 字数 331 浏览 3 评论 0原文

我正在开发一个巨大的 Python 模块,如下所示:

import millions, and, billions, of, modules...

...lots of functions...

def myfunc
   ...with huge body

...more functions

我想将 myfunc 提取到它自己的模块中。然而,追踪我需要的所有进口实际上是相当乏味的。有没有办法使用 Eclipse 自动执行此操作?我正在使用 Eclipse 3.7.0 和 Aptana Studio 插件(以及 PyDev)。有一个“提取方法”重构工具,但它不这样做。

I'm working on a huge Python module, like this:

import millions, and, billions, of, modules...

...lots of functions...

def myfunc
   ...with huge body

...more functions

I'd like to extract myfunc to its own module. However, tracking down all the imports I need is actually pretty tedious. Is there a way to do this automatically using Eclipse? I'm using Eclipse 3.7.0 with Aptana Studio plugin (and hence PyDev). There's an "extract method" refactoring tool, but it doesn't do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肩上的翅膀 2024-12-24 11:34:20

好吧,也许这比我想象的要容易:

  1. 将函数定义复制到新文件
  2. 将整个导入部分复制到该新文件
  3. 未使用的导入用一条摆动的黄线显示。删除它们。
  4. 从原始文件中删除函数定义,并将其替换为调用引用。
  5. 现在这里也有未使用的导入,因此请按照 3 删除它们。

它不是自动的,但相对简单且轻松。

Ok, maybe this is easier than I thought:

  1. Copy function definition to a new file
  2. Copy the entire imports section to that new file
  3. Unused imports are shown with a wiggly yellow line. Delete them.
  4. Delete the function definition from the original file, replacing it with a call reference.
  5. Now you have unused imports here too, so delete those as per 3.

It's not automatic, but it's relatively straightforward and painless.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文