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

Python os.chown() method

Python os.chown() method

Python File methods Python OS file/directory methods


Overview

The os.chown() method changes the owner of a file; if it should not be changed it can be set to -1. You need superuser privileges to perform the permission change.

Only supported on Unix.

Syntax

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



os.chown(path, uid, gid);

Parameters

Return Value

This method has no return value.

Example

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

Example

#!/usr/bin/python

-- coding: UTF-8 --

import

os

,

sys

Assume the file /tmp/foo.txt exists.

Set the owner ID to 100

os

.

chown

(

"/tmp/foo.txt"

,

100

,

1

)

print

"Permission changed successfully!!"

The output of the above program is:



修改权限成功!!

Python File methods Python OS file/directory methods