Python 导入';兄弟姐妹';模块相互转换?

Python 导入';兄弟姐妹';模块相互转换?,python,python-module,Python,Python Module,所谓“同级”模块,我指的是父模块中存在于同一深度的两个子模块 我正在尝试使用flask Restful创建一个flask项目,它建议使用以下模式构建项目: myapi/ __init__.py app.py # this file contains your app and routes resources/ __init__.py foo.py # contains logic for /Foo

所谓“同级”模块,我指的是父模块中存在于同一深度的两个子模块

我正在尝试使用flask Restful创建一个flask项目,它建议使用以下模式构建项目:

myapi/
    __init__.py
    app.py          # this file contains your app and routes
    resources/
        __init__.py
        foo.py      # contains logic for /Foo
        bar.py      # contains logic for /Bar
    common/
        __init__.py
        util.py     # just some common infrastructure

我真的很喜欢这种结构,但我不知道如何从“公共”模块导入“资源”模块。有人能帮我吗?

common/\uuu init\uuuu.py

from myapi.common.utils import A, B
from myapi.common import A
resource/foo.py

from myapi.common.utils import A, B
from myapi.common import A

如果将
foo.py
bar.py
导入
resources/\uu init\uuuuuuuupy
中,您还可以像从.utils导入A一样在
中进行相对导入,我很确定您可以从myapi执行
。resources import foo,bar
。如果你想做相反的事,同样的逻辑也适用。谢谢,这正是我想要的。