import sys import os base_dir = os.path.dirname(os.path.abspath(__file__))sys.path.append(base_dir)
os.path.abspath(__file__) 确认*.py的绝对路径
os.path.dirname(os.path.abspath(__file__)) 返回*.py的上一级文件路径 sys.path.append(base_dir) 添加搜索路径
本文共 283 字,大约阅读时间需要 1 分钟。
import sys import os base_dir = os.path.dirname(os.path.abspath(__file__))sys.path.append(base_dir)
os.path.abspath(__file__) 确认*.py的绝对路径
os.path.dirname(os.path.abspath(__file__)) 返回*.py的上一级文件路径 sys.path.append(base_dir) 添加搜索路径
转载于:https://www.cnblogs.com/ystwyfe/p/7512242.html