python 不一样层级目录下导入,只能导入包,若是要导入包就必须在包下创建__init__.py 文件 。须要用sys.path.append(path) 将要导入包的路径添加到须要导入的文件中。这个路径是包的上层目录。好比python
路径以下app
--dira函数
----dirbit
-------test1.pytest
-------__init__.py
import
--dirc引用
----dird
im
------test2.py
di
若是在这个路径关系下test2.py 想要引用test1.py 中的函数,那么在test2.py 中必须添加sys.path.append("../../dira")文件
而后import dirb.test1
使用函数必须为dirb.test1.fun()