Eryk Sun <[email protected]> added the comment:
The drive is retained when a rooted path is joined to a drive-absolute or
UNC-absolute path. This is documented behavior [1]:
When several absolute paths are given, the last is taken as an
anchor (mimicking os.path.join()’s behaviour):
>>> PurePath('/etc', '/usr', 'lib64')
PurePosixPath('/usr/lib64')
>>> PureWindowsPath('c:/Windows', 'd:bar')
PureWindowsPath('d:bar')
However, in a Windows path, changing the local root doesn’t
discard the previous drive setting:
>>> PureWindowsPath('c:/Windows', '/Program Files')
PureWindowsPath('c:/Program Files')
If you want to simply append directories to a path, use a relative path. For
example:
>>> Path('C:/Program Files') / Path('one/two/three.exe')
WindowsPath('C:/Program Files/one/two/three.exe')
[1]: https://docs.python.org/3/library/pathlib.html#pathlib.PurePath
----------
nosy: +eryksun
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36334>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com