How to move to one folder back in python

后端 未结 7 2182
眼角桃花
眼角桃花 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:38

    think about using absolute paths

    import os
    pwd = '/home/Desktop/folder'
    
    if some_condition == true :
        path = os.path.join(pwd, "nodes/hellofolder")
        os.chdir(path)
        print os.getcwd()
    if another_condition  == true:
        path = os.path.join(pwd, "nodes")
        os.chdir(path) 
        print os.getcwd()
    

提交回复
热议问题