开发者

How can I achieve something like "from foo.bar import baz.qux"?

I have a few packages that include modules named util, so that it becomes difficult to tell which util module is referred to if you see something like this:

util.some_func()

What I would like to do is something like this:

views.util.some_func()

...but I can't figure out a good way to import this. Of course this doesn't work:

from apture.main import views.util

The best I can come up with is to add from . import views in views/__init__.py, and then do this:

from apture.main import views
views.util.some_func()

Is there 开发者_Python百科any better way to do this? The only other alternative I can think of is:

import apture.main.views.util
from apture.main import views

views.util.some_func()

...but that's a bit ugly.


Would this work for you:

  from apture.main.view import util as view_util
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜