Getting original working directory

David Stanek dstanek at dstanek.com
Thu Sep 6 15:03:38 EDT 2007


On 9/6/07, rave247 rave247 <rave247 at seznam.cz> wrote:
>
> If I could use os.getcwd() or save the value to some variable before
> calling os.chdir() I would do it, believe me. However I can't because it
> is the part of code where I can't do any changes.


Why is it not possible. If nothing else create a new module that does the
os.getcwd() then call the module that you cannot change.

Also I do not agree that such thing is not possible because after python
> script finishes its work, it naturally gets back into the original location
> from where you started the script (in shell you are in the original location
> after script finishes). So this information has to be stored somewhere
> (probably in shell which runs the interpreter) and there *must*  be a way
> how to get it. Simply after calling os.chdir() the original value doen't
> disappear, I think it just needs some nice hack if python doesn't provide a
> way how to get it.
>

The shell is back to where it started for a very different reason. I won't
go into it, because it's not about Python. However, if you know what shell
you will *always* be using to run the script, then there may be a way. Bash,
for example, will have the path where you were when the script started in
os.environ['PWD']. I suspect most shells have something similar.


David
--
http://www.traceback.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070906/f26282c5/attachment.html>


More information about the Python-list mailing list