python: get directory two levels up

后端 未结 12 1936
清歌不尽
清歌不尽 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:41

    Personally, I find that using the os module is the easiest method as outlined below. If you are only going up one level, replace ('../..') with ('..').

        import os
        os.chdir('../..')
    
    --Check:
        os.getcwd()
    

提交回复
热议问题