29 Nov
2013
29 Nov
'13
5:54 p.m.
On Wed, 30 Oct 2013 10:06:03 -0700 Bruce Leban <bruce@leapyear.org> wrote:
I agree it might be confusing but it's pretty explicitly documented. On the other hand, this is also documented and it's wrong by the above standard
os.path.join(r'c:\abc', r'\def\g') # Windows paths '\\def\\g'
On Windows \def\g is a drive-relative path not an absolute path. To get the right result you need to do:
drive, path = os.path.splitdrive(r'c:\abc') drive + os.path.join(path, r'/def/g') 'c:/def/g'
Note that pathlib gets it right:
PureWindowsPath(r'c:\abc') / r'\def\g' PureWindowsPath('c:/def/g')
PureWindowsPath(r'\\abc\def\ghi') / r'\x\y' PureWindowsPath('//abc/def/x/y')
Regards Antoine.