Python os.readlink() Method

Python File(文件) 方法Python OS File/Directory Methods


Overview

The os.readlink() method is used to return the file pointed to by a symbolic link. It 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 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'

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

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

The output of the above program is:

/usr/bin/python

Python File(文件) 方法Python OS File/Directory Methods

Other Extensions