Eryk Sun <[email protected]> added the comment:
> and b / a gives me WindowsPath('/a/b'). So I'm like "ok, a seems
> like absolute, I will test for that" but on Windows a.is_absolute()
> is False.
Path.is_absolute() is true if a path has a `root` and, for a Windows path, also
a `drive`.
In C++, the filesystem::path is_absolute() method is similar. In Windows it's
true if both has_root_name() (i.e. a drive) and has_root_directory() are true.
In POSIX it just depends on has_root_directory(). pathlib.Path is also
consistent with C++ filesystem::path with regard to appending paths with the
slash operator [1]. I would prefer for it to remain so.
FYI, in Windows, "/a/b" is resolved using the drive of the process current
working directory, which may be a UNC path. The drive of a UNC path is the
share path, such as "\\server\share".
Another type of relative path in Windows is a drive-relative path, which
applies to drive-letter drives only. For example:
>>> Path('C:spam') / "eggs"
WindowsPath('C:spam/eggs')
>>> Path('C:spam') / "/eggs"
WindowsPath('C:/eggs')
"C:spam" is relative to the current working directory on drive "C:". The API
gets the working directory for the target drive either from the process current
working directory, if it's a path on the target drive, or from an "=<drive
letter>:" environment variable, such as "=Z:". (The Windows API allows
environment variable names to begin with "=".) If the process current working
directory is on a different drive, and the environment variable for the target
drive isn't set, the API defaults to using the root directory on the target
drive. Setting these per-drive working directory environment variables is up to
the application. Python's os.chdir() supports them.
---
[1] https://en.cppreference.com/w/cpp/filesystem/path/append
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue44452>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com