在Python 3.6中,可以使用以下方式正确导入项目目录中的模块或包:
project/
main.py
utils/
helper.py
在main.py中导入helper.py可以使用相对导入:
from .utils import helper
project/
main.py
utils/
helper.py
在main.py中导入helper.py可以使用绝对导入:
from project.utils import helper
需要注意的是,Python 3.6默认支持隐式相对导入,即可以直接使用相对导入语法,而无需在文件开头添加from __future__ import absolute_import
语句。
以上是Python 3.6在项目目录中正确导入方式的示例。对于具体的项目结构和导入需求,可以根据实际情况选择适合的导入方式。
领取专属 10元无门槛券
手把手带您无忧上云