Reputation: 4401
We can change the current directory in the shell :
username@hostname:~/f1$ cd ~/f2
username@hostname:~/f2$
is it possible to write a python (v2.7 and / or v3) which changes the current directory to one programatically determined ?
E.g.
username@hostname:~/f1$ python change_dir.py
username@hostname:~/f2$
Upvotes: 1
Views: 64
Reputation: 19375
As chepner and Sraw correctly said, a child process cannot change the current directory of its parent. So, what you can do is to let the Python program output the desired directory and use this output in a cd
command:
cd `python print_dir.py`
Upvotes: 1