Getting original working directory
Steve Holden
steve at holdenweb.com
Thu Sep 6 15:13:25 EDT 2007
rave247 rave247 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.
>
> 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.
>
Python runs as a sub-process. The parent process (the one that started
Python) contains the working directory that the Python interpreter
inherited from it. But you can't expect to just go poking around inside
the environment of your parent process, which will typically be waiting
for you to finish before it continues. Why *must* there be a way to get
at its current directory? Once it continues, of course, it does so in
the same directory. If you want to hack into your parent process to find
that information that's up to you, but Python certainly has no special
mechanism for doing it.
If you treat the answers to all your questions with so little respect
it's a wonder you bother asking the questions in the first place.
You didn't even explain what the relationship was between the "myscript"
that you want to run and the Python code that you want to switch back to
the original working directory. Sorry, we aren't mind readers (though
some of the guys on this list get close on occasion).
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
More information about the Python-list
mailing list