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

Python os.symlink() method

Python os.symlink() method

Python File methods Python OS file/directory methods


Overview

The os.symlink() method creates a symbolic link.

A symbolic link is a special file type that contains a reference to another file or directory and can point to different locations in the file system.

Syntax

The **symlink()** method syntax is as follows:



os.symlink(src, dst)

Parameters

Return Value

This method has no return value.

Example

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

Example

#!/usr/bin/python

-- coding: UTF-8 --

import

os

src

=

'

/usr/bin/python

'

dst

=

'

/tmp/python

'

Create a symbolic link

os

.

symlink

(

src

,

dst

)

print

"

Symbolic link created successfully

"

The output of the above program is:

软链接创建成功

Python File methods Python OS file/directory methods