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

Python3 os.readlink() Method

Python3 os.readlink() Method

Python3 OS File/Directory Methods Python3 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/python3

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

Python3 OS File/Directory Methods Python3 OS File/Directory Methods