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:HPPycharmProjectsJDMerchantdebug
当前目录的父目录_方式一: E:HPPycharmProjectsJDMerchant
系统目录分隔符:
当前目录的父目录_方式二:E:HPPycharmProjectsJDMerchant
http_case_path: E:HPPycharmProjectsJDMerchanthttpCase