Python3 os.symlink() Method
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
src: The path of the target file or directory for which the symbolic link is created.dst: The path and name of the symbolic link.target_is_directory(optional): a Boolean value specifying whethersrcis a directory. If set to True,dstwill be created as a symbolic link pointing to a directory.
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
)
(
"
Symbolic link created successfully
"
)
The output of the above program is:
软链接创建成功