如何从 customer_helper_test.py 导入 CustomerHelper 类到 customer_helper.py 中?这是可能的?我使用了 from ..helpers..tests..app.helpers.customer_helper import CustomerHelper 但它是无效语法。
这里是组织的文件夹:
program/
app/
helpers/
customer_helper.py
__init__.py
__init__.py
tests/
helpers/
customer_helper_test.py
__init__.py
__init__.py
__init__.py
提前致谢!
请您参考如下方法:
始终努力使用绝对导入。
from program.app.helpers.customer_helper import CustomerHelper
如果出于某种原因你绝对不能,那么
from ...app.helpers.customer_helper import CustomerHelper
请注意,app 无论如何都必须是一个包。
