Issue
Actually need to go some path and execute some command and below is the code
code:
import os
present_working_directory = '/home/Desktop/folder'
presently i am in folder
if some_condition == true :
change_path = "nodes/hellofolder"
os.chdir(change_path)
print os.getcwd()
if another_condition == true:
change_another_path = "nodes"
os.chdir(change_another_path)
print os.getcwd()
**Result**:
'/home/Desktop/folder/nodes/hellofolder'
python: [Errno 1] No such file or directory
Actually whats happening here is when i first used os.chdir()
the directory has changed to
'/home/Desktop/folder/nodes/hellofolder'
,
but for the second one i need to run a file by moving to one folder back that is
'/home/Desktop/folder/nodes'
So can anyone let me how to move one folder back in python
Solution
Just like you would in the shell.
os.chdir("../nodes")
Answered By - Alex
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.