Latest web development tutorials

Python3 os.chroot () method

Python3 OS file / directory methods Python3 OS file / directory methods


Outline

os.chroot () method is used to change the root directory of the current process to the specified directory, use this function requires administrator privileges.

grammar

chroot () method syntax is as follows:

os.chroot(path);

parameter

  • path - to be set to the root directory.

return value

This method has no return value.

Examples

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

#!/usr/bin/python3

import os, sys

# 设置根目录为 /tmp

os.chroot("/tmp")

print ("修改根目录成功!!")

The above program output is:

修改根目录成功!!

Python3 OS file / directory methods Python3 OS file / directory methods