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

Python3 os.symlink() Method

Python3 os.symlink() Method

Python3 OS File/Directory Methods Python3 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, target_is_directory=False)

Parameters

Return Value

This method has no return value.

Example

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

Example

#!/usr/bin/python3

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:

软链接创建成功

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