Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python os.readlink() method

Python os.readlink() method

Python File methods 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

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

Python File methods Python OS file/directory methods