os.join Windows action

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Colin J. Williams

    #1

    os.join Windows action

    I am puzzled by the Windows XP usage below:

    C:\Python23\Lib \site-packages\PyMatr ix>c:python23\p ython
    The system cannot find the path specified.

    C:\Python23\Lib \site-packages\PyMatr ix>c:python23\p ython.exe
    The system cannot find the path specified.

    C:\Python23\Lib \site-packages\PyMatr ix>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\PyMatr ix>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

    #2
    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

    Comment

    • John Machin

      #3
      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

      Comment

      Working...