Issue 693416: 2.3a2 import after os.chdir difference (original) (raw)

Created on 2003-02-26 04:42 by jrut, last changed 2022-04-10 16:07 by admin. This issue is now closed.

Messages (4)
msg14854 - (view) Author: James P Rutledge (jrut) Date: 2003-02-26 04:42
In Python 2.3a2 in interactive mode an import after an os.chdir imports the module in the new current directory after the os.chdir. This is the same as Python 2.2.2 does both in interactive and non-interactive mode. In Python 2.3a2 in non-interactive mode an import after an os.chdir does not import the module in the new current directory after the os.chdir. Instead it attempts to import a module (if present) by that name in the previous current directory before the os.chdir. If there is not a module by that name in the previous current directory, there is an ImportError exception. The above results are on a Debian Linux system using an Intel 32 bit processor. No PYTHONSTARTUP environment variable was set. No PYTHONPATH environment variable was set.
msg14855 - (view) Author: James P Rutledge (jrut) Date: 2003-02-26 14:31
Logged In: YES user_id=720847 Additional Info -- I have now tried more than one os.chdir before the import in non-interactive mode and found that the words "previous current directory" in the original description should be more accurately expressed as "ORIGINAL current directory."
msg14856 - (view) Author: Aaron Brady (insomnike) Date: 2004-06-05 20:00
Logged In: YES user_id=1057404 Right, I'm nearly sure that this is the behaviour that we want. When run interactively, the first item in sys.path is '', but when run from a script, it is the path to the directory that the script lives in. If we reverted to the 2.2.2 behaviour, multi-module scripts couldn't use os.chdir() for fear of randomly breaking imports.
msg14857 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2004-06-29 12:11
Logged In: YES user_id=11375 Closing, because this isn't a bug.
History
Date User Action Args
2022-04-10 16:07:09 admin set github: 38055
2003-02-26 04:42:57 jrut create