我试图理解如何将属于同一项目的python文件拆分到不同的目录中。如果我理解正确,我需要使用here in the documentation所描述的包。你知道吗
所以我的结构是这样的:
.
├── A
│ ├── fileA.py
│ └── __init__.py
├── B
│ ├── fileB.py
│ └── __init__.py
└── __init__.py
有空的__init__.py
文件和
$ cat A/fileA.py
def funA():
print("hello from A")
$ cat B/fileB.py
from A.fileA import funA
if __name__ == "__main__":
funA()
现在我希望在执行B/fileB.py
时得到"Hello from A"
,但得到的却是以下错误:
ModuleNotFoundError: No module named 'A'
我做错什么了?你知道吗
您的问题与:Relative imports for the billionth time相同
作为主要:
输出:
作为模块(非主模块):
输出:
解决这个问题的一种方法是将模块
A
添加到文件b.py通过添加到山顶文件b.py. 你知道吗
相关问题 更多 >
编程相关推荐