python 获取当前文件夹路径及父级目录的几种方法

获取当前文件夹路径及父级目录:

import os
current_dir = os.path.abspath(os.path.dirname(__file__))
print(current_dir) #F:\project\pritice

current_dir1 = os.path.dirname(__file__)
print(current_dir1) #F:/project/pritice

parent_path = os.path.dirname(current_dir1)
print(parent_path) #F:/project

parent_path1  = os.path.dirname(parent_path)
print(parent_path1) #F:/

parent_path2 = os.path.dirname(current_dir)
print(parent_path2) #F:\project

 

posted @ 2018-11-30 20:59  小呆丶  阅读(20007)  评论(0编辑  收藏  举报