You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any reason why there is no equivalent of os.readlink in pathlib.Path? Note that Path.resolve does *not* fit the bill, as it always produces an absolute path, whereas readlink just spits out the symlink target exactly the way it is stored, which may be relative to the symlink itself:
>>> import pathlib, os
>>> p = pathlib.Path("/lib64/libc.so.6")
>>> p.resolve()
PosixPath('/lib64/libc-2.24.so')
>>> os.readlink(str(p))
'libc-2.24.so'
Activity
smheidrich commentedon Jun 9, 2017
Is there any reason why there is no equivalent of os.readlink in pathlib.Path? Note that Path.resolve does *not* fit the bill, as it always produces an absolute path, whereas readlink just spits out the symlink target exactly the way it is stored, which may be relative to the symlink itself:
girtsf commentedon Jun 23, 2018
Just ran into the same thing. I would be interested in adding support for a "readlink" call if a pull request on this would be welcome.
berkerpeksag commentedon Aug 30, 2018
The resolve() method already solves symlinks, but I think this is a reasonable feature request. I've just reviewed PR 8285.
miss-islington commentedon Oct 23, 2019
New changeset a01ba33 by Miss Skeleton (bot) (Girts) in branch 'master':
bpo-30618: add readlink to pathlib.Path (GH-8285)
a01ba33
gpshead commentedon Oct 23, 2019
Thanks Girts!