How to get the parent dir location

前端 未结 11 1970
鱼传尺愫
鱼传尺愫 2020-12-07 10:34

this code is get the templates/blog1/page.html in b.py:

path = os.path.join(os.path.dirname(__file__), os.path.join(\'templates\', \'blog1/page.html\'))
         


        
11条回答
  •  [愿得一人]
    2020-12-07 11:08

    os.pardir is a better way for ../ and more readable.

    import os
    print os.path.abspath(os.path.join(given_path, os.pardir))  
    

    This will return the parent path of the given_path

提交回复
热议问题