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

Python3 os.chroot() Method

Python3 os.chroot() Method

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


Overview

The os.chroot() method changes the root directory of the current process to the specified directory; using this function requires administrator privileges.

Valid on Unix.

Syntax

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


os.chroot(path);

Parameters

Return Value

This method has no return value.

Example

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


#!/usr/bin/python3

import os, sys

# Set root directory to /tmp

os.chroot("/tmp")

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

The output of the above program is:

修改根目录成功!!

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