Change cwd in the underlying shell from Python script?

PoD pod at internode.on.net
Tue Apr 24 13:01:40 EDT 2001


ben at co.and.co wrote:
> 
> Joakim Hove <hove at phys.ntnu.no> wrote:
> > bash:/original/path$ myscript.py
> >
> >   [The Python script goes through a "serious calculation", and finds
> >    the new path "/new/path/to/where/I/want/tobe".
> >
> >    When the script is finished the cwd of the underlying shell has
> >    been changed to this new path.]
> >
> > bash:/new/path/to/where/I/want/tobe$
> >
> > Is something like this possible?
> 
> No. The cwd is a property of a process. You can change directories
> anywhere you want in your Python script, but it won't influence the
> parent process (bash).
> 
> Greetings,
> --

But you could have your Python script output the new path on stdout, then
bash:cd `calcpath.py`

Cheers, PoD.



More information about the Python-list mailing list