Python 导入';兄弟姐妹';模块相互转换?
所谓“同级”模块,我指的是父模块中存在于同一深度的两个子模块 我正在尝试使用flask Restful创建一个flask项目,它建议使用以下模式构建项目: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
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
。如果你想做相反的事,同样的逻辑也适用。谢谢,这正是我想要的。