import sys
sys.setdefaultencoding('utf-8')
sys.path.append("你想导入的包的路径")
#接下来即可引用其他目录下的模块
from [包].[包].[.py文件] import [方法]
一个python包中必须有__init__.py 文件才能被识别为python包。切__init__.py中必须声明同级目录下所有.py文件中 [....].py 的方括号部分,否则from ... import * 时会出现部分模块导入不了的问题。
#__init__.py文件
__all__ = ["hello",]
转载于:https://www.cnblogs.com/the-moon-so-beautiful/p/8436977.html
相关资源:25个经典网站源代码