Python模块调用时的路径查找

 

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) 添加搜索路径


 
posted @ 2017-09-12 21:13  ystwyfe  阅读(158)  评论(0编辑  收藏  举报