【发布时间】:2020-12-12 19:56:46
【问题描述】:
- 如何从 b1.py 导入到 b2.py
- 如何从 sa1 导入 b2?
test/ # root folder
packA/
subA/
__init__.py
sa1.py
sa2.py
__init__.py
a1.py
a2.py
packB/
b1.py
b2.py
math.py
random.py
other.py
start.py
编辑 通过放置解决它:
import os
import sys
sys.path.append(os.getcwd())
其中 os.getcwd() 是项目的根目录。
【问题讨论】:
-
这能回答你的问题吗? Relative imports for the billionth time