Monkey 修补和调度

发布于 2024-12-09 16:13:15 字数 325 浏览 4 评论 0原文

我有以下情况,一个名为 enthought.chaco2 的模块,并且我有很多导入,例如 from enthought.chaco.api import ..

那么添加 < code>chaco.api 并使其分派到正确的位置?

例如,我尝试了一些方法:

import enthought.chaco2 as c2
import enthought
enthought.chaco = c2

但它不起作用。我可能必须创建一个真正的模块并将其添加到路径中;这是唯一的方法吗?

I have the following situation, a module called enthought.chaco2 and I have many imports, like from enthought.chaco.api import ..

so what's the quickest way to add chaco.api and make it dispatch to the correct one?

I tried a few things, for example:

import enthought.chaco2 as c2
import enthought
enthought.chaco = c2

but it doesn't work. I might have to create a real module and add it to the path; is that the only way?

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

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

发布评论

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

评论(1

-柠檬树下少年和吉他 2024-12-16 16:13:15

您正在寻找什么行为?

您可以使用 from enthought.chaco import api as ChacoApi ,然后通过 ChacoApi 处理模块中的任何内容,例如 ChacoApi.foo()chaco_class = ChacoApi.MyClass()

您可以使用(但不推荐)from enthought.chaco.api import * 并将模块的所有内容添加到您的基本命名空间中。
您可以将 __all__ 变量声明添加到 chaco__init__.py 文件中,并让前面的示例(带有 *)仅导入您想要的内容输入列表__all__

或者您可以专门导入您现在可能使用的任何内容,我认为这完全没问题......

What is the behavior you're looking for?

You could use from enthought.chaco import api as ChacoApi and then address any content from the module through ChacoApi, like ChacoApi.foo() or chaco_class = ChacoApi.MyClass().

You could use (and that's not recommended) from enthought.chaco.api import * and have all the content of the module added to your base namespace.
You could add an __all__ variable declaration to chaco's __init__.py file and have the previous example (with the *) only import what you entered the list __all__.

Or you could import specifically any content you might use the way you do right now which is perfectly fine in my opinion...

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