Connecting Tech Pros Worldwide Forums | Help | Site Map

os.join Windows action

Colin J. Williams
Guest
 
Posts: n/a
#1: Jul 18 '05
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.[color=blue][color=green][color=darkred]
>>> ^Z[/color][/color][/color]

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.[color=blue][color=green][color=darkred]
>>>[/color][/color][/color]

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.





Michael Hoffman
Guest
 
Posts: n/a
#2: Jul 18 '05

re: os.join Windows action


Colin J. Williams wrote:
[color=blue]
> C:\XXX is required, C:XXX is not acceptable.[/color]

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:.
[color=blue]
> How should os.path.join('C:', 'ugh') be treated?[/color]

Exactly as it is? If you want other behavior, you want
os.path.join('C:\\', 'ugh').
--
Michael Hoffman
John Machin
Guest
 
Posts: n/a
#3: Jul 18 '05

re: os.join Windows action



Michael Hoffman wrote:[color=blue]
> Colin J. Williams wrote:
>[color=green]
> > C:\XXX is required, C:XXX is not acceptable.[/color]
>
> 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:.[/color]

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

Closed Thread