ntpath bug or expected?

jepler at unpythonic.net jepler at unpythonic.net
Wed Sep 11 21:57:58 EDT 2002


On Thu, Sep 12, 2002 at 01:18:21AM +0000, dsavitsk wrote:
> python 2.1.3.  this is pretty minor ... os.path.join() on win32 fails if the
> first path component is C: (or any other letter).  that is, if the first
> component is a drive letter, it must contain either '\\' or '/' or else the
> path is wrong.  this makes it the only component which must have slashes.
> 
> example
> >>> os.path.join('C:', 'path', 'to', 'file.txt')
> C:path\\to\\file.txt

Sure.  This is the file on drive C which is in the relative path
"path\\to\\file.txt" from the current directory of drive C.

Remember, DOS maintains a separate working directory for each drive.

A first element of C:/ would make the path absolute, and a first element of
C: would make the path relative to the current directory of C.  I think
that is why
    >>> ntpath.join("C:", "/path", "to", "file.txt")
    'C:/path\\to\\file.txt'
is "correct".  This is the one I wonder about, though:
    >>> ntpath.join("C:", "/a", "/b", "x.txt")
    '/b\\x.txt'
    >>> ntpath.join("C:/a", "/b", "x.txt")
    '/b\\x.txt'
if the drive letter is preserved in my first example, why isn't it in the
last two?

Jeff




More information about the Python-list mailing list