Getting original working directory
gherron at islandtraining.com
Thu Sep 6 17:50:20 CEST 2007
rave247 rave247 wrote:
> I' am unable to solve this problem. I've got python program, it is installed in standard location. I run this program from some location X (note that I just type relative "myscript", leaving operating system to look up script itself using PATH variable) and this program somewhere in the code calls os.chdir() to change it is current working directory and I would need in python code to get the *original* directory location *after* os.chdir() is performed. This means the location X from which script was performed - it is the location I am in after script is finished.
> Thanks for any help
Not quite sure what you want, but one of these should work for you:
sys.argv gives the path of the script begin run. Strip off the
filename part to get its directory.
os.getcwd() returns the current working directory. Call this before you
change things with os.chdir().
More information about the Python-list