[英]What is the most pythonic way to import 'sibling' modules into one another?
通过“兄弟”模块,我的意思是在父模块中存在于相同深度的两个子模块。
我正在尝试使用 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”模块导入到“resources”模块中。 谁能帮我吗?
common/__init__.py
from myapi.common.utils import A, B
在resource/foo.py
from myapi.common import A
您还可以在__init__.py
相对导入,例如from .utils import A
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.