Re: [Python-Dev] Re: Change to sys.path[0] for Python 2.3
4) For the "-c" option, sys.argv[0] is getcwd() instead of "".
A related issue: what is sys.path[0] for an interactive interpreter? I customarily use Python as a shell, and os.chdir() from one place to another, importing things along the way. Would an interactive interpreter keep the "" entry in sys.path[0]? -- Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++ Jack.Jansen@oratrix.com | ++++ if you agree copy these lines to your sig ++++ www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm
Jack Jansen wrote:
4) For the "-c" option, sys.argv[0] is getcwd() instead of "".
A related issue: what is sys.path[0] for an interactive interpreter? I customarily use Python as a shell, and os.chdir() from one place to another, importing things along the way. Would an interactive interpreter keep the "" entry in sys.path[0]?
The proposal is to put getcwd() into sys.path[0] for an interactive interpreter. So after os.chdir(), imports would NOT be made from the new current directory, but rather from the original current directory. If this is a problem (I'm guessing it is) then the new rule would be: sys.path[0] is the absolute path to the script if there is one; else for an interactive interpreter or for the "-c" option, sys.path[0] is the special entry "" (or perhaps ".") that means look in the current directory (which is allowed to change). In either case, sys.path[0] would be added before any imports. I am not happy with changing current directories because I am trying to speed up imports, and it is harder to cache directory contents on multiple operating systems. But I can do it if we need to. A special case for "." is not too bad, but accommodating arbitrary relative paths is more of a problem. What do others think? JimA
James C. Ahlstrom writes: | | The proposal is to put getcwd() into sys.path[0] for an interactive | interpreter. So after os.chdir(), imports would NOT be made from | the new current directory, but rather from the original current | directory. | | If this is a problem (I'm guessing it is) then the new rule would be: | | sys.path[0] is the absolute path to the script if there is one; else | for an interactive interpreter or for the "-c" option, sys.path[0] | is the special entry "" (or perhaps ".") that means look in the | current directory (which is allowed to change). | | In either case, sys.path[0] would be added before any imports. | | I am not happy with changing current directories because I am trying | to speed up imports, and it is harder to cache directory contents | on multiple operating systems. But I can do it if we need to. | | A special case for "." is not too bad, but accommodating arbitrary | relative paths is more of a problem. | | What do others think? | As little as I like it, we have lots and lots of code here that depends on chdir to find modules for importing. If you were to make this change (and I suspect you won't because it might break lots of code, but for argument's sake...) would having an explicit '.' somewhere in sys.path still work after a chdir?
Tommy 'Too Many Stances' Burnette wrote:
As little as I like it, we have lots and lots of code here that depends on chdir to find modules for importing. If you were to make this change (and I suspect you won't because it might break lots of code, but for argument's sake...) would having an explicit '.' somewhere in sys.path still work after a chdir?
My current thinking is that "" and "." on sys.path need to work after a chdir. So you could still chdir and import from the new current directory. Harder is the question of whether 'Path/To/Lib' should work after a chdir. It is a relative path, but not simply "" nor ".". Don't panic, I am not changing anything until we all decide what we want. JimA
participants (3)
-
Jack Jansen
-
James C. Ahlstrom
-
Tommy 'Too Many Stances' Burnette