The first method found by auto-complete on a pathlib.Path
is absolute()
.
It seems to just prepend Path.cwd() at the start:
>>> from pathlib import Path
>>> path = Path('./relative/path') / '../with/some/../relative/parts'
Path('relative/path/../with/some/../relative/parts')
# calling absolute...
>>> absolute_path = path.absolute()
Path('/[current_dir]/relative/path/../with/some/../relative/parts')
# does the same as prepending cwd at the start
>>> Path.cwd() / path
Path('/[current_dir]/relative/path/../with/some/../relative/parts')
However, Path.absolute()
is not listed in the pathlib documentation.
Compare this to Path.resolve(), which does the opposite (replace relative parts but don't prepend cwd
) and is documented.
Can I use absolute()
or should I avoid it?