Python中在脚本中引用其他文件函数的实现方法

yangwelcom 8 0 PDF 2020-12-31 19:12:10

在导入文件的时候,Python只搜索当前脚本所在的目录,加载(entry-point)入口脚本运行目录和sys.path中包含的路径例如包的安装地址。所以如果要在当前脚本引用其他文件,除了将文件放在和脚本同一目录下,还有以下几种方法, 1. 将文件所在位置添加到sys.path中 import sys sys.path.insert(0, '/path/to/application/app/folder') # or sys.path.append('/path/to/application/app/folder') import file 2. 在文件目录下新建__init__.py文件然

用户评论
请输入评论内容
评分:
暂无评论