Eryk Sun <[email protected]> added the comment:
> I mean,os.path.join('3', '{:3') return '{:3' in windows, However,
> os.path.join('3', '{:3') return '3/{:3'in linux, output result not
> '3' in windows, why?
The implementation of ntpath.join handles "{:" as a drive. Thus "{:3" is a
drive-relative path, i.e. "3" is relative to the current working directory on
drive "{:".
In particular, for each joined component, ntpath.join calls ntpath.splitdrive,
which splits at the second character if it's a colon, regardless of the first
character. For example:
>>> ntpath.splitdrive('{:3')
('{:', '3')
As demonstrated in my previous post, the Windows file API supports drive names
that use any basic multilingual plane (BMP) character, including symbol
characters such as "{". So the long-standing behavior of ntpath.splitdrive in
this regard is generally right. Except it shouldn't allow the first character
to be a path separator, i.e. the following result is nonsense:
>>> ntpath.splitdrive('/:/spam')
('/:', '/spam')
> with path '{:3' you open file with name '3' in the current
> directory of drive '{'
The drive name would be "{:", not "{". It's a common usage, for example, to
call "C:" the "C" drive, but the drive name actually includes the colon. This
differs from the usage of colon in file streams, in which the colon is a
delimiter that's not part of the name.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41565>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com