posixpath.abspath and symlinks
Jeff Epler
jepler at unpythonic.net
Wed Jan 28 12:34:46 EST 2004
On Wed, Jan 28, 2004 at 10:37:39PM +0530, Sidharth Kuruvila wrote:
> i dont know unix.
> how does abs path work with sym-links.
os.abspath does not check whether any components are symlinks. In the
presence of symlinks,
/a/../b
and
/b
can refer to separate files if /a is a symlink to a directory. As far as
I know, posixpath.abspath normalizes the first into the second anyway.
Similarly, if you have a symlink
/a -> c
then posixpath.abspath("a") doesn't return /c, it still returns /a
You can use os.readlink() on posix systems to get the thing a symlink
points to:
>>> os.readlink("/proc/self")
'14717'
>>> os.readlink("/")
OSError: [Errno 22] Invalid argument: '/'
Jeff
More information about the Python-list
mailing list