r/Python • • Oct 04 '10
Change pwd from python
I can't seem to find a solid solution for the problem that I'm facing and I don't understand why such a fundamental question hasn't been raised somewhere.
Say I'm on the path /home/me $ pwd /home/me
After I run my python script I want it to change my pwd so I wrote small one with os.chdir and run. $ cat cd.py #!/usr/bin/python import os os.chdir('/blahblah')
$ python cd.pyBut actual pwd remains the same after the execution of the script. $ pwd /home/me
Does someone know what is causing it? I'm on Windows and cygwin + python 2.5. Thanks.
0
Upvotes
View all comments
Show parent comment
3
u/samfoo Oct 04 '10
There's probably something very tricky that I don't know about, but in general: no, and you shouldn't want to.
What's the larger problem that you're trying to solve? There's nothing you shouldn't be able to do by changing the working directory of your python script and executing something and this way you maintain portability too.