How to move to one folder back in python

后端 未结 7 2047
眼角桃花
眼角桃花 2021-01-30 09:10

Actually need to go some path and execute some command and below is the code

code:

import os
present_working_directory = \'/home/Desktop         


        
7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 09:47

    Exact answer for your question is os.chdir('../')

    Use case:

    Folder1:
        sub-folder1:(you want to navigate here)
    Folder2:
        sub-folde2:(you are here)
    

    To navigate to sub-folder1 from sub-folder2, you need to write like this "../Folder1/sub-folder1/"

    then, put it in os.chdir("../Folder1/sub-folder1/").

提交回复
热议问题