Python os.fchown() method
Python OS file/directory methods
Overview
The os.fchown() method changes the ownership of a file; this function changes the user ID and group ID of the file specified by the file descriptor fd.
Available on Unix.
Syntax
The **fchown()** method syntax is as follows:
os.fchown(fd, uid, gid)
Parameters
-
fd -- The file descriptor
-
uid -- The user ID of the file owner
-
gid -- The group ID of the file owner
Return Value
This method has no return value.
Example
The following example demonstrates the use of the fchown() method:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys, stat
# Open file "/tmp/foo.txt"
fd = os.open( "/tmp", os.O_RDONLY )
# Set the file's user ID to 100
os.fchown( fd, 100, -1)
# Set the file's group ID to 100
os.fchown( fd, -1, 50)
print "修改权限成功!!"
# Close file
os.close( fd )
The output of the above program is:
修改权限成功!!