[英]Problem importing nested package in Python
Based from a project with the following structure:基于具有以下结构的项目:
.
└── src/
├── main.py
├── PackageA/
│ ├── __init__.py
│ ├── logic.py
│ ├── SubPackageA1/
│ │ ├── __init__.py
│ │ └── util.py
│ └── SubPackageA2/
│ ├── __init__.py
│ └── otherUtil.py
└── PackageB/
├── __init__.py
└── helpers.py
It would be possible to import in the file helpers.py the package otherutil.py?可以在文件 helpers.py 中导入 package otherutil.py 吗?
All the combinations I tried until now fail.到目前为止,我尝试过的所有组合都失败了。
If your program is executed from main.py the import in helpers.py should work like this:如果您的程序是从 main.py 执行的,则 helpers.py 中的导入应该像这样工作:
from PackageA.SubPackageA2 import otherUtil
Yes, I checked it, main.py:是的,我查过了,main.py:
from PackageB import helpers
print(helpers.HELPERS_UTIL)
otherUtil.py:其他工具.py:
OTHER_UTIL = 'test'
helpers.py助手.py
from PackageA.SubPackageA2 import otherUtil
HELPERS_UTIL = otherUtil.OTHER_UTIL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.