Python3 os.chown() Method
Python3 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:
#!/usr/bin/python3
import os, sys
# Assume /tmp/foo.txt file exists.
# Set owner ID to 100
os.chown("/tmp/foo.txt", 100, -1)
print ("修改权限成功!!")
The output of the above program is:
修改权限成功!!