Easy Tutorial
❮ Python Os Lchmod Python Os Pipe ❯

Python3 os.readlink() Method

Python3 OS File/Directory Methods


Overview

The os.readlink() method is used to return the path to which the symbolic link points, which may be either an absolute or relative path.

Valid on Unix.

Syntax

The syntax for the readlink() method is as follows:

os.readlink(path)

Parameters

Return Value

Returns the path to which the symbolic link points.

Example

The following example demonstrates the use of the readlink() method:

#!/usr/bin/python3

import os

src = '/usr/bin/python'
dst = '/tmp/python'

# Create a symbolic link
os.symlink(src, dst)

# Display the source link using the symbolic link
path = os.readlink(dst)
print(path)

Executing the above program will output:

/usr/bin/python

Python3 OS File/Directory Methods

❮ Python Os Lchmod Python Os Pipe ❯