os.join Windows action

  • Thread starter Colin J. Williams
  • Start date
C

Colin J. Williams

I am puzzled by the Windows XP usage below:

C:\Python23\Lib\site-packages\PyMatrix>c:python23\python
The system cannot find the path specified.

C:\Python23\Lib\site-packages\PyMatrix>c:python23\python.exe
The system cannot find the path specified.

C:\Python23\Lib\site-packages\PyMatrix>c:\python23\python.exe
Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
C:\Python23\Lib\site-packages\PyMatrix>c:\python23\python
Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
C:\XXX is required, C:XXX is not acceptable.

The os.path.join doc has:

*join*( path1[, path2[, ...]])

Joins one or more path components intelligently. If any
component is an absolute path, all previous components are
thrown away, and joining continues. The return value is the
concatenation of path1, and optionally path2, etc., with exactly
one directory separator (|os.sep|) inserted between components,
unless path2 is empty. Note that on Windows, since there is a
current directory for each drive, os.path.join("c:", "foo")
represents a path relative to the current directory on drive C:
(c:foo), not c:\\foo.

How should os.path.join('C:', 'ugh') be treated?

Colin W.
 
M

Michael Hoffman

Colin said:
C:\XXX is required, C:XXX is not acceptable.

C:XXX is acceptable, it just means something entirely different from
C:\XXX. There is a current working directory on each drive. C:XXX is
file XXX in the current directory on drive C:.
How should os.path.join('C:', 'ugh') be treated?

Exactly as it is? If you want other behavior, you want
os.path.join('C:\\', 'ugh').
 
J

John Machin

Michael said:
C:XXX is acceptable, it just means something entirely different from
C:\XXX. There is a current working directory on each drive. C:XXX is
file XXX in the current directory on drive C:.

Further notes for Colin:

On *x, /xxx is the xxx file in the root directory and xxx is the xxx
file in the current directory. Same perceived problem.

This is not a new feature in Windows XP; it has been as Michael
described ever since directories were introduced in MS-DOS 2.0. And of
course it applies to all file paths, irrespective of whether you want
to execute / read /write / etc.

As a matter of interest, do you normally run python with
"site-packages" as the current directory? Most folk would not do that,
with any software package, preferring the installed software to be just
that, and not "polluted" with their own data etc which should be kept
elsewhere in appropriately named and structured directories.

HTH,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top