获取编写代码所在文件的上级文件和上上级文件的相对路径

import os 

当前程序的执行路径:

 os.path。abspath('.')

 上级路径:

os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))

上级路径的父路径:

os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) 

posted @ 2018-01-11 14:52  python许三多  阅读(218)  评论(0编辑  收藏  举报