[issue39090] Document various options for getting the absolute path from pathlib.Path objects
New submission from Brett Cannon
Chris Barker
Change by Josh Holland
Paul Moore
In short -- I understand that this is a complex issue, but making an absolute path is a pretty common use case, and we've had os.path.abspath() for decades, so there should be one obvious way to do it, and it should be easily discoverable.
+1 on this.
Given that (as far as I can tell from the various discussions) `resolve` works fine as long as the file exists, maybe the key distinction to make is whether you have an existing file or not.
(More subtle questions like UNC path vs drive letter, mentioned on the Discourse thread, are probably things that we can defer to a "more advanced cases" discussion in the docs).
----------
nosy: +paul.moore
_______________________________________
Python tracker
Floris Lambrechts
Paul Moore
Floris Lambrechts
Vedran Čačić
Floris Lambrechts
Floris Lambrechts
Floris Lambrechts
Not mentioning Path.resolve()'s behavior w.r.t. non-existing files since
John Hennig
from pathlib import Path file = Path('new.txt') file.exists() False file.resolve() PosixPath('/home/user/new.txt')
Windows:
Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:44:55) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.
from pathlib import Path file = Path('new.txt') file.exists() False file.resolve() WindowsPath('new.txt') file.absolute() WindowsPath('d:/home/new.txt') file.touch() file.resolve() WindowsPath('D:/home/new.txt') file.unlink() file.resolve() WindowsPath('new.txt')
----------
nosy: +John-Hennig
_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue39090>
_______________________________________
Change by 4-launchpad-kalvdans-no-ip-org
participants (8)
-
4-launchpad-kalvdans-no-ip-org
-
Brett Cannon
-
Chris Barker
-
Floris Lambrechts
-
John Hennig
-
Josh Holland
-
Paul Moore
-
Vedran Čačić