On 9/17/19, Cameron Simpson <c...@cskk.id.au> wrote:
>
> If you just want this for your running program's internals this may not
> matter, but if you're recording the result somewhere then abspath might
> get you a more "stable" path in the above scenario.

If a path has ".." components, the abspath() result may be wrong if it
resolves them by removing a parent symlink. The absolute() method of
pathlib.Path does this right by retaining ".." components.

    >>> os.path.abspath('/foo/symlink/../bar')
    '/foo/bar'

    >>> pathlib.Path('/foo/symlink/../bar').absolute()
    PosixPath('/foo/symlink/../bar')

abspath() is also the wrong choice if we're computing the target path
for a relative symlink via relpath(). A relative symlink is evaluated
from the parsed path of its parent directory.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to