Re: [Python-Dev] Change to sys.path[0] for Python 2.3
I'm not too thrilled about this, especially not in the 2.2 release cycle. The sys.path logic is difficult, and everytime a change was made on one platform this change immedeately broke things on all other platforms. For instance: on the Mac full pathnames are not necessarily unique. Or another example: on unix you could have your working directory in /foo/bar/bletch and access ./blurgh.py there, but not access /foo/bar/bletch/blurgh.py: /foo/bar could be unsearchable for you. And the "python -c" mod I really disagree with. 'python -c "import foo"' in the directory containing foo.py is the standard way of using this, which you would break.
I have been working on import.c and thinking about imports generally. Currently, the directory of the Python script is inserted into sys.path[0]. For example, "python /A/B/myscript.py" creates sys.path[0] = "/A/B", and "python myscript.py" creates sys.path[0] = "". But there are three problems.
This insertion occurs after a number of imports have already occurred. Specifically, it occurs after the import of site, os, and sitecustomize. This is confusing. It is clear that sys.path should not change unless the user changes it.
If no path component is given, the zero length string is inserted. But if the current working directory later changes, this is no longer valid. If we want the directory of the script to be sys.path[0], then an absolute path should be inserted.
If a command is entered using "-c", I don't think any insertion to sys.path should be made, as there is no indicated directory. Alternatively, the absolute path getcwd() should be inserted.
If everyone agrees, I will create a patch.
Jim Ahlstrom
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev
-- 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
"Barry A. Warsaw" wrote:
I'm sure Jim wasn't talking about this for 2.2, unless he'd gone temporarily insane. :)
As part of my job, I have been writing a lot of Fortran lately,
and I notice that Fortran has a lot of great features that are
missing from Python. For example, Fortran's three-way IF statement
is obviously better than Python's two way "if". And the Fortran
common block has the ability to modify any item by using out-of-bounds
array references, without having to worry about pesky type mismatches.
And have I mentioned the versatile GOTO statement, and its convenient
alternative spellings "GO TO" and "GO TO"?
In fact, I plan to write up another PEP on features which need to
be added to Python based on the only real [wo]mans programming
language, namely Fortran. It should be done any day as soon
as I come up for air and have t*/e to t>^~k of al& the f@#tu!es
I #?
"JCA" == James C Ahlstrom
writes:
JCA> In fact, I plan to write up another PEP on features which JCA> need to be added to Python based on the only real [wo]mans JCA> programming language, namely Fortran. ------------------------------------------^^^ so close and yet so far... s/ran/h/-ly y'rs, -Barry
Jack Jansen wrote:
I'm not too thrilled about this, especially not in the 2.2 release cycle. The sys.path logic is difficult, and everytime a change was made on one platform this change immedeately broke things on all other platforms. For instance: on
I agree, and I am very worried about breaking imports on platforms which I do not have, and which I can not test. But I am working on zip imports, which is a Good Thing. While working on this I can fix other things which don't seem quite right. If things break, I currently have time to fix them due to reduced pressure at work. And of course it is for 2.3, not 2.2.
And the "python -c" mod I really disagree with. 'python -c "import foo"' in the directory containing foo.py is the standard way of using this, which you would break.
OK, I think you are right here. The "-c" option should insert the current directory. Currently it inserts "". JimA
participants (3)
-
barry@zope.com
-
Jack Jansen
-
James C. Ahlstrom