Python os.chown() method
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
-
path -- The path of the file whose permissions are set
-
uid -- The owner user ID
-
gid -- The owner group ID
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
)
"Permission changed successfully!!"
The output of the above program is:
修改权限成功!!