Change cwd in the underlying shell from Python script?

Grant Edwards grante at visi.com
Tue Apr 24 12:41:08 EDT 2001


In article <UzhF6.5480$qc2.2151171 at typhoon.southeast.rr.com>, Steve  Holden wrote:

>> >   [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).

>However, what you *could* do is:
>
>In the parent process, issue the command:
>
>PATH=$PATH:`pathcalculator.py`; export PATH

I think that 

 cd `pathcalculator.py`
 
is more along the lines of what the OP had in mind.  You could
wrap that in a shell function or alias to make it a bit more
user-friendly.

-- 
Grant Edwards                   grante             Yow!  I smell like a wet
                                  at               reducing clinic on Columbus
                               visi.com            Day!



More information about the Python-list mailing list