日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python獲取當前文件路徑以及父文件路徑的方法

系統 1724 0

python獲取當前文件路徑以及父文件路徑的方法_第1張圖片

            
#當前文件的路徑
pwd = os.getcwd()
#當前文件的父路徑
father_path=os.path.abspath(os.path.dirname(pwd)+os.path.sep+".")
#當前文件的前兩級目錄
grader_father=os.path.abspath(os.path.dirname(pwd)+os.path.sep+"..")
          

追加部分代碼實例

            
def TestPrtPwd(self):
    print("獲取當前文件路徑――" + os.path.realpath(__file__)) # 獲取當前文件路徑
    parent = os.path.dirname(os.path.realpath(__file__))
    print("獲取其父目錄――" + parent) # 從當前文件路徑中獲取目錄
    garder = os.path.dirname(parent)
    print("獲取父目錄的父目錄――" + garder)
    print("獲取文件名" + os.path.basename(os.path.realpath(__file__))) # 獲取文件名
    # 當前文件的路徑
    pwd = os.getcwd()
    print("當前運行文件路徑" + pwd)
    # 當前文件的父路徑
    father_path = os.path.abspath(os.path.dirname(pwd) + os.path.sep + ".")
    print("運行文件父路徑" + father_path)
    # 當前文件的前兩級目錄
    grader_father = os.path.abspath(os.path.dirname(pwd) + os.path.sep + "..")
    print("運行文件父路徑的父路徑" + grader_father)
    return garder
          

運行結果:

            
獲取當前文件路徑――D:\SVN\測試\autotest\functionalAutomation\aonr_sxsj\AuditData\common\redConfig.py
獲取其父目錄――D:\SVN\測試\autotest\functionalAutomation\aonr_sxsj\AuditData\common
獲取父目錄的父目錄――D:\SVN\測試\autotest\functionalAutomation\aonr_sxsj\AuditData
獲取文件名redConfig.py
當前運行文件路徑D:\SVN\測試\autotest\functionalAutomation\aonr_sxsj\AuditData\TestSuite\RoleManagement
運行文件父路徑D:\SVN\測試\autotest\functionalAutomation\aonr_sxsj\AuditData\TestSuite
運行文件父路徑的父路徑D:\SVN\測試\autotest\functionalAutomation\aonr_sxsj\AuditData
          

python獲取當前文件路徑以及父文件路徑的方法_第2張圖片

以上這篇python獲取當前文件路徑以及父文件路徑的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 丹棱县| 玛纳斯县| 屏东市| 龙岩市| 界首市| 平安县| 抚远县| 保靖县| 蓬溪县| 茌平县| 马尔康县| 昆明市| 巴中市| 宜宾县| 崇义县| 栖霞市| 望江县| 积石山| 江川县| 麟游县| 肥城市| 虎林市| 迭部县| 阳信县| 武隆县| 兰考县| 新巴尔虎左旗| 依兰县| 天气| 即墨市| 金堂县| 客服| 闽侯县| 黄冈市| 大姚县| 蒙阴县| 古蔺县| 青州市| 张掖市| 丽江市| 丽水市|