python学习------路径转换

_file_:内置变量,执行脚本的当前相对路径

os.path.abspath(_file_):返回当前位置的绝对路径

os.path.dirname(os.path.abspath(_file_)):返回当前执行脚本文件所在目录

 

应用:BASE_DIR=os.path.dirname(os.path.dirname(os.path.abspath(_file_)))

os.path.append(BASE_DIR)

posted @ 2018-09-25 11:32  yujin123456  阅读(272)  评论(0编辑  收藏  举报