28.10.2021 Views

Python Tutorial ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Syntax

Following is the syntax for fchmod() method:

os.fchmod(fd, mode);

Parameters

• fd -- This is the file descriptor for which mode would be set.

• mode -- This may take one of the above mentioned values or bitwise ORed combinations of them.

Return Value

This method does not return any value.

Example

The following example shows the usage of fchmod() method.

#!/usr/bin/python

import os, sys, stat

# Now open a file "/tmp/foo.txt"

fd = os.open( "/tmp", os.O_RDONLY )

# Set a file execute by the group.

os.fchmod( fd, stat.S_IXGRP)

# Set a file write by others.

os.fchmod(fd, stat.S_IWOTH)

print "Changed mode successfully!!"

# Close opened file.

os.close( fd )

Let us compile and run the above program, this will produce the following result:

Changed mode successfully!!

os.fchown(fd, uid, gid)

TUTORIALS POINT

Simply Easy Learning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!