Monkey 修补和调度
我有以下情况,一个名为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找什么行为?
您可以使用
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 throughChacoApi
, likeChacoApi.foo()
orchaco_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 tochaco
'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...