os.path获取当前路径及父路径

import os

pwd = os.getcwd()
print("当前目录: " + pwd)

father_path_method1 = os.path.dirname(pwd)
print("当前目录的父目录_方式一: " + father_path_method1)

separator = os.path.sep
print("系统目录分隔符: " + separator)

father_path_method2=os.path.abspath(os.path.dirname(pwd)+os.path.sep+".")
print("当前目录的父目录_方式二:"  + father_path_method2)

http_case_path = os.path.join(os.path.dirname(pwd),"httpCase")
print("http_case_path: " + http_case_path)

输出结果如下:

当前目录: E:\HP\PycharmProjects\JDMerchant\debug
当前目录的父目录_方式一: E:\HP\PycharmProjects\JDMerchant
系统目录分隔符: \
当前目录的父目录_方式二:E:\HP\PycharmProjects\JDMerchant
http_case_path: E:\HP\PycharmProjects\JDMerchant\httpCase

 

posted @ 2020-06-29 10:44  pandaly  阅读(3726)  评论(0编辑  收藏  举报