Python3 os.fchown () method
Python3 OS file / directory methods
Outline
os.fchown () method is used to change the ownership of a file, this function modifies a file's user ID and group ID, the file specified by the file descriptor fd.
Available on Unix.
grammar
fchown () method syntax is as follows:
os.fchown(fd, uid, gid)
parameter
fd - file descriptor
uid - user id file's owner
user group id owner of the file- gid
return value
This method has no return value.
Examples
The following example demonstrates fchown () method of use:
#!/usr/bin/python3 import os, sys, stat # 打开文件 "/tmp/foo.txt" fd = os.open( "/tmp", os.O_RDONLY ) # 设置文件的用户 id 为 100 os.fchown( fd, 100, -1) # 设置文件的用户组 id 为 100 os.fchown( fd, -1, 50) print ("修改权限成功!!") # 关闭文件 os.close( fd )
The above program output is:
修改权限成功!!