Python3 os.readlink() Method

Python3 OS 文件/目录方法Python3 OS File/Directory Methods


Overview

The os.readlink() method is used to return the file pointed to by a symbolic link, which may return an absolute or relative path.

Valid on Unix

Syntax

readlink()The method syntax is as follows:

os.readlink(path)

Parameters

  • path-- The symbolic link path to query

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'

# 创建软链接
os.symlink(src, dst)

# 使用软链接显示源链接
path = os.readlink( dst )
print (path)

The output of executing the above program is:

/usr/bin/python

Python3 OS 文件/目录方法Python3 OS File/Directory Methods

Other Extensions