Changing a shell's current directory with python
Peter Hansen
peter at engcorp.com
Sun Dec 18 20:36:48 EST 2005
Andy B. wrote:
> I've got a python utility that I want to change my shell's current
> directory based on criteria it finds. I've scoured google and the
> python cookbook and can't seem to figure out if this is even possible.
> So far, all my attempts have changed the current python session only.
> Am I going to have to wrap this in a shell script?
As you've heard, you can't get there from here. In fact, even just
wrapping with a shell script likely won't be enough, unless you are
willing to "source" the script every time you run it. The only way I
know of (and I'd be happy to hear alternatives) to do this in a
_transparent_ manner is to combine an alias (which uses "source" for
you) with a wrapper script _and_ to have that wrapper script read from
some place (stdout or a temporary file or ?) to which the Python script
can communicate the desired new environment variables and/or current
directory.
-Peter
More information about the Python-list
mailing list