Python os.readlink() method
Python OS file/directory methods
Overview
The os.readlink() method returns the file pointed to by a symbolic link. It may return an absolute or relative path.
Valid on Unix
Syntax
The **readlink()** method syntax is as follows:
os.readlink(path)
Parameters
-
path -- The path of the symbolic link to look up
Return Value
Returns the file pointed to by the symbolic link
Example
The following example demonstrates the use of the readlink() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
src = '/usr/bin/python'
dst = '/tmp/python'
# Create symbolic link
os.symlink(src, dst)
# Use symlink to show source link
path = os.readlink( dst )
print path
The output of the above program is:
/usr/bin/python