Easy Tutorial
❮ Python Swap Variables Ref Math Ceil ❯

Python3 os.fchmod() Method

Python3 OS File/Directory Methods


Overview

The os.fchmod() method is used to change the access permissions of a file specified by the file descriptor fd. The mode parameter represents the Unix file access permissions.

Available on Unix.

Syntax

The syntax for the fchmod() method is as follows:

os.fchmod(fd, mode);

Parameters

Return Value

This method does not return any value.

Example

The following example demonstrates the use of the fchmod() method:

#!/usr/bin/python3

import os, sys, stat

# Open the file "/tmp/foo.txt"
fd = os.open("/tmp", os.O_RDONLY)

# Set the file to be executable by the group
os.fchmod(fd, stat.S_IXGRP)

# Set the file to be writable by others
os.fchmod(fd, stat.S_IWOTH)

print("Permissions changed successfully!!")

# Close the file
os.close(fd)

Executing the above program will output:

Permissions changed successfully!!

Python3 OS File/Directory Methods

❮ Python Swap Variables Ref Math Ceil ❯