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

Python os.fchown() method

Python os.fchown() method

Python File methods 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

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:



修改权限成功!!

Python File methods Python OS file/directory methods