python: get directory two levels up

后端 未结 12 1932
清歌不尽
清歌不尽 2021-01-30 06:00

Ok...I dont know where module x is, but I know that I need to get the path to the directory two levels up.

So, is there a more elegant way to do:

         


        
12条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 06:39

    I have found that the following works well in 2.7.x

    import os
    two_up = os.path.normpath(os.path.join(__file__,'../'))
    

提交回复
热议问题