Easy Tutorial
❮ Python Celsius Fahrenheit Home ❯

Python3 os.chmod() Method

Python3 OS File/Directory Methods


Overview

The os.chmod() method is used to change the permissions of a file or directory.

Available on Unix systems.

Syntax

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

os.chmod(path, mode)

Parameters

Return Value

This method does not return a value.

Example

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

#!/usr/bin/python3

import os, sys, stat

# Assuming /tmp/foo.txt exists, set the file to be executable by the group

os.chmod("/tmp/foo.txt", stat.S_IXGRP)

# Set the file to be writable by others
os.chmod("/tmp/foo.txt", stat.S_IWOTH)

print("Modification successful!!")

Executing the above program will output:

Modification successful!!

Python3 OS File/Directory Methods

❮ Python Celsius Fahrenheit Home ❯